Home › Developer Tools › Nginx Config Generator

Nginx Config Generator

Answer a few questions and get a clean, commented nginx server block. It covers static sites, single-page apps, reverse proxies (with WebSockets and load balancing) and PHP-FPM, plus HTTPS with modern TLS settings, redirects, gzip, caching and security headers.

Last updated:

Server
HTTPS
Performance & security
Redirects

Generated configuration

    Advertisement
    Advertisement

    How to use the Nginx Config Generator

    1. Choose the site type: static files, a single-page app (React, Vue, Angular), a reverse proxy to an app server, or PHP.
    2. Enter your domain names and the document root or backend address.
    3. Set up HTTPS: keep Let's Encrypt paths or enter your own certificate files, and pick HTTP/2, HSTS and the www redirect you want.
    4. Tune performance and security: gzip, asset caching, security headers, upload limit and custom redirects.
    5. Copy or download the config, save it in /etc/nginx/sites-available/ or /etc/nginx/conf.d/, run sudo nginx -t and reload nginx.

    How nginx picks a location

    Inside a server block nginx chooses one location per request. Knowing the order avoids most "why is this rule ignored?" problems:

    1. Exact match location = /path wins immediately.
    2. The longest prefix match is remembered. If it uses ^~, it wins and regexes are skipped.
    3. Regular expressions ~ (case-sensitive) and ~* (case-insensitive) are checked in the order they appear in the file; the first match wins.
    4. If no regex matches, the remembered longest prefix (for example location /) is used.

    Common nginx directives

    DirectivePurpose
    server_nameHost names this server block answers. Use _ as a catch-all.
    root / indexFolder that holds the files, and the file served for a directory request.
    try_files $uri $uri/ /index.htmlTry the file, then the folder, then fall back to index.html (SPA routing).
    return 301 https://$host$request_uriPermanent redirect that keeps the path and query string.
    proxy_pass http://127.0.0.1:3000Forward the request to an app server. With a URI part, the matched prefix is replaced.
    proxy_set_headerPass Host, client IP and protocol to the backend.
    expires 30dSets Expires and Cache-Control: max-age for browser caching.
    add_header … alwaysAdd a response header, also on error pages. Headers are not inherited by a location that defines its own add_header.
    client_max_body_size 20MLargest upload allowed (default 1 MB, larger requests get 413).
    gzip onCompress text responses; add the MIME types in gzip_types.

    Troubleshooting checklist

    • Always test first: sudo nginx -t prints the file and line of any syntax error. Reload with sudo systemctl reload nginx so running connections are not dropped.
    • 502 Bad Gateway: the backend is not running or listens on a different port or socket. Check it with curl http://127.0.0.1:3000 on the server and read /var/log/nginx/error.log.
    • 403 Forbidden on a static site: the nginx user (www-data or nginx) needs read access to the files and execute access to every parent folder.
    • Default page still shows: remove or disable sites-enabled/default, or make sure your server_name matches the domain you are requesting.
    • Redirect loop behind a load balancer or Cloudflare: the proxy talks to nginx over HTTP, so redirecting to HTTPS loops. Use the proxy's HTTPS settings or check $http_x_forwarded_proto.

    Frequently asked questions

    Where do I put the nginx config file?

    On Debian and Ubuntu, save it as /etc/nginx/sites-available/example.com.conf and symlink it into /etc/nginx/sites-enabled/. On RHEL, Fedora, Alpine and the official Docker image, save it in /etc/nginx/conf.d/ with a .conf extension. Then test with sudo nginx -t and apply with sudo systemctl reload nginx.

    How do I redirect HTTP to HTTPS in nginx?

    Add a server block that listens on port 80 for your domains and contains return 301 https://$host$request_uri; (or your canonical domain instead of $host). The generator creates this block when you enable HTTPS and the redirect option.

    How do I make nginx serve a React or Vue single-page app?

    Use try_files $uri $uri/ /index.html; in location /. Requests for real files are served directly and every other path falls back to index.html, so the client-side router can handle it. Choose the Single-page app type to get this plus sensible caching.

    What headers should a reverse proxy pass to the backend?

    At least Host, X-Real-IP, X-Forwarded-For and X-Forwarded-Proto, so the app knows the original host, client IP and whether the request used HTTPS. For WebSockets you also need proxy_http_version 1.1 and the Upgrade and Connection headers.

    Why does nginx -t fail with a certificate error?

    The ssl_certificate files must exist before nginx loads the config. Get the certificate first (for example sudo certbot certonly --nginx -d example.com), or start with HTTPS turned off, obtain the certificate, then enable HTTPS.

    Should I use listen 443 ssl http2 or http2 on?

    Since nginx 1.25.1 the http2 parameter of listen is deprecated in favour of the separate http2 on; directive. Use the new syntax on current nginx and the legacy syntax only for older versions such as 1.18 or 1.22 shipped by some distributions.

    Is anything sent to a server?

    No. The configuration is generated in your browser and your settings are only saved in this browser's local storage.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.Dockerfile GeneratorGenerate a production Dockerfile and .dockerignore for Node, Python, Go or a static nginx site.Docker Run to Compose ConverterConvert docker run commands to docker-compose.yml, or a compose file back to docker run.Robots.txt GeneratorBuild a robots.txt file with rules, sitemap lines and AI-bot blocking presets.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.Random String GeneratorGenerate secure random strings and tokens in bulk with any length and character set.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.Gitignore GeneratorBuild a .gitignore from 50+ templates for languages, frameworks, IDEs and OS, merged and deduped.License GeneratorCreate a LICENSE file for MIT, Apache, GPL, BSD, ISC, MPL or Unlicense with your name and year.ULID GeneratorGenerate sortable ULIDs and UUID v7 in bulk, monotonic option, and decode their timestamps.Htpasswd GeneratorCreate .htpasswd entries with bcrypt, APR1-MD5 or SHA-1 for Apache and Nginx basic auth.Placeholder Image GeneratorCreate placeholder images in any size, color and text as PNG, JPG, WebP, SVG or data URI.Ads.txt GeneratorCreate or validate ads.txt and app-ads.txt files: seller lines, cert IDs and variables.HTML Boilerplate GeneratorTick the options you need and get a clean HTML5 starter template with meta, OG tags and CSS reset.JSON to Zod SchemaInfer a Zod (or Yup) schema from sample JSON with optional, nullable and z.infer types.Linux Commands Cheat SheetSearchable Linux and bash command reference with flags explained, examples and copy buttons.LLMs.txt GeneratorBuild an llms.txt file for AI crawlers: summary and link sections, import from your sitemap.Nano ID GeneratorGenerate secure Nano IDs with custom alphabet, length and count, plus a collision calculator.OpenAPI / Swagger ViewerView OpenAPI 2/3 JSON or YAML as interactive API docs with validation and an endpoint list.package.json GeneratorFill a form and get a valid, npm-ready package.json with scripts, dependencies and checks.PKCE Code Challenge GeneratorGenerate an OAuth 2.0 PKCE code_verifier and S256 code_challenge, build auth URLs, verify pairs.README GeneratorFill in a form and get a polished README.md with badges, install, usage and license, live preview.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Commit Message GeneratorBuild Conventional Commit messages with type, scope, body, breaking change and issue refs.Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.Docker Compose GeneratorBuild a docker-compose.yml with a form: services, ports, volumes, env, healthchecks and presets.Dummy File GeneratorCreate test files of an exact size in KB, MB or GB with zeros, random bytes or text.FFmpeg Command GeneratorPick a task and options, get the exact ffmpeg command with every flag explained.Folder Tree GeneratorTurn a local folder or an indented list into an ASCII directory tree for your README.GitHub Actions Workflow GeneratorBuild a GitHub Actions CI workflow: triggers, matrix, caching, tests, Pages or Docker deploy.HowTo Schema GeneratorCreate HowTo JSON-LD with steps, tools, supplies, total time and cost, then copy it.Htaccess GeneratorBuild an Apache .htaccess file: HTTPS, www, gzip, caching, error pages, IP blocks, hotlinks.HTML Email Template BuilderDrag and drop blocks to build a responsive, table-based HTML email with inline styles.Organization Schema GeneratorCreate Organization JSON-LD with logo, URL, contact points, address and social profiles.PIN GeneratorGenerate random 4, 6 or 8-digit PINs that avoid sequences, repeats, dates and common PINs.Product Schema GeneratorBuild Product JSON-LD with price, availability, brand, GTIN, ratings and reviews.Question Keyword GeneratorFind the questions people ask about a topic, grouped by who, what, why, how, can and more.Recipe Schema GeneratorCreate Recipe JSON-LD with ingredients, steps, prep and cook times, nutrition and ratings.Security Headers GeneratorPick HSTS, CSP, frame, referrer and permissions options and get Apache, Nginx, Netlify or Cloudflare config.SKU GeneratorBuild consistent SKUs from brand, category, size and color, then export every variant as CSV.Typography Scale GeneratorBuild a modular type scale from a base size and ratio, then copy CSS variables or a Tailwind config.WordPress Salt GeneratorGenerate fresh WordPress security keys and salts for wp-config.php, .env or Docker in one click.ANSI Color Code GeneratorStyle terminal text with 16, 256 or RGB colors and get escape codes for bash, Python, JS and C.Apache Virtual Host GeneratorCreate an Apache VirtualHost config with SSL, redirects, reverse proxy or PHP-FPM in seconds.Bash Prompt GeneratorDrag and drop a custom PS1 prompt for bash or zsh with colors, git branch and a live preview.Changelog GeneratorTurn Conventional Commit messages into a grouped Keep a Changelog Markdown file per version.cURL Command BuilderBuild curl commands from a form: method, headers, query, JSON or form body, auth and flags.Docker Compose to KubernetesConvert docker-compose.yml into Kubernetes Deployment, Service, ConfigMap and PVC manifests.Docker Compose ValidatorCheck a docker-compose.yml for YAML errors, schema mistakes, broken references and deprecated keys.Dockerfile LinterLint a Dockerfile for best practices: pinned tags, apt cleanup, non-root USER and layer count.Dockerignore GeneratorBuild a .dockerignore from Node, Python, Go and Java templates, plus your own entries.ESLint Config GeneratorGenerate a flat eslint.config.js for JavaScript, TypeScript, React or Node with rule presets.Git Branch Name GeneratorTurn a ticket ID and title into a clean, valid git branch name like feature/PROJ-12-add-login.GitLab CI Config GeneratorGenerate a .gitlab-ci.yml with stages, jobs, images, cache, artifacts and rules from templates.Jinja2 Template TesterRender Jinja2 templates with YAML or JSON variables using real Jinja2, with clear error lines.JSON Schema Mock Data GeneratorGenerate realistic sample JSON from a JSON Schema: formats, patterns, $ref, seeds and counts.Kubernetes Secret GeneratorCreate Kubernetes Secret YAML from key/value pairs or .env with auto base64, or decode one.Kubernetes YAML ValidatorValidate Kubernetes manifests against the API schema of a chosen version, with error paths.Prettier Config GeneratorToggle Prettier options, preview formatted code live and copy your .prettierrc file.Quartz Cron GeneratorBuild and explain Quartz and Spring cron expressions with seconds, ?, L, W and #, plus next fire times.
    See all 85 Code Generators & Builders →