01What is Nginx Config Generator?
Writing an nginx server block from memory is where small mistakes creep in. A missing proxy header, an HSTS line on plain HTTP, or a cache rule that drops your security headers. This generator builds the block from a short form, so you start from a config that already avoids those traps. You pick one of five use cases: Reverse Proxy, Static Site, Single Page App, Redirect or Load Balancer. Each one writes a different location / block. The reverse proxy passes requests to your app with proxy_http_version 1.1 and the Host, X-Real-IP, X-Forwarded-For and X-Forwarded-Proto headers. Tick WebSocket support and it adds the Upgrade and Connection headers too. The static site uses try_files $uri $uri/ =404 plus custom 404 and 50x error pages. The SPA falls back to your index file so client-side routes load. The load balancer adds an upstream block with round robin, least_conn or ip_hash, and writes weight= only when a server's weight is above 1, since 1 is nginx's default. Turning on SSL adds a second server on port 80 that returns 301 to https://$host$request_uri. The HTTPS server uses listen 443 ssl with the separate http2 on directive. The nginx docs mark the old listen ... http2 parameter as deprecated since 1.25.1. Protocols are TLS 1.2 and 1.3, and the cipher list follows Mozilla's intermediate profile. The HSTS header is only written on the HTTPS server, because RFC 6797 says browsers ignore it over plain HTTP. The other options cover gzip, three security headers (X-Frame-Options, X-Content-Type-Options and Referrer-Policy), client_max_body_size, and a limit_req zone of 10 requests per second per IP with a burst of 20. Asset caching uses expires instead of add_header. That matters because nginx drops inherited add_header lines in any location that sets its own. Here is a quick example. Choose Single Page App with root /var/www/html and caching at 30d. You get try_files $uri $uri/ /index.html, a regex location that sets expires 30d on CSS, JS, images and fonts, and a second one that sets expires -1 on .html files. Assets stay cached for a month while HTML is revalidated, so a fresh deploy shows up on the next visit. There are limits. The output is one site, meant for a conf.d file included inside the http block. It won't write proxy timeouts, buffering, Content-Security-Policy or certificate issuance. The redirect target is used exactly as typed, so paths aren't kept unless you add $request_uri yourself. Always run nginx -t before you reload.
Backend developers and sysadmins who need a correct nginx server block for one site, such as a proxied app, an SPA or a domain redirect, without writing it from scratch. The tool runs entirely in your browser, so your data never leaves your device.
02How to use Nginx Config Generator
- Under Use Case, pick Reverse Proxy, Static Site, Single Page App, Redirect or Load Balancer.
- Fill in Server Name and Listen Port, then the fields for your case: Proxy Pass URL, Root Path and Index File, Redirect URL and Redirect Code, or Upstream Name, Method and Upstream Servers.
- Under Options, tick Enable SSL / HTTPS (then set SSL Cert Path and SSL Key Path), Gzip Compression, Static Asset Caching, Rate Limiting or Security Headers, and set Client Max Body Size.
- Copy or download the config and save it as a file under /etc/nginx/conf.d/.
- Run nginx -t, then reload nginx once the test passes.
03Worked examples
- Input:
Reverse proxy, example.com, port 80, proxy to http://localhost:3000, gzip, caching and security headers off - Result:
server { listen 80; listen [::]:80; server_name example.com; client_max_body_size 10m; location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } - The comment header the tool adds above each config is left out here.
- Input:
Redirect, old.example.com -> https://new.example.com, 301 - Result:
server { listen 80; listen [::]:80; server_name old.example.com; … location / { return 301 https://new.example.com; } } - The target has no $request_uri, so every path on the old host goes to the new site's home page; add $request_uri to the URL if you want to keep paths.
- Input:
Load balancer, upstream backend, least_conn, servers 10.0.0.2:3000 weight 3 and 10.0.0.3:3000 weight 1 - Result:
upstream backend { least_conn; server 10.0.0.2:3000 weight=3; server 10.0.0.3:3000; } server { … location / { proxy_pass http://backend; … } } - weight=1 is nginx's default, so it isn't written out.
- Input:
SPA, root /var/www/html, index.html, caching 30d on - Result:
root /var/www/html; index index.html; location / { try_files $uri $uri/ /index.html; } location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 30d; } location ~* \.html$ { expires -1; } - Assets are cached for 30 days, but HTML gets expires -1, which nginx sends as Cache-Control: no-cache. Only the inside of the server block is shown, with inline comments removed.
- Input:
Reverse proxy, example.com, Enable SSL / HTTPS on, other options off, Client Max Body Size empty - Result:
server { listen 80; listen [::]:80; server_name example.com; return 301 https://$host$request_uri; } server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name example.com; ssl_certificate /etc/ssl/certs/cert.pem; ssl_certificate_key /etc/ssl/private/key.pem; ssl_protocols TLSv1.2 TLSv1.3; … - Trimmed after the protocols line. The cipher list, session settings and location / block follow. The http2 line also carries a comment about older nginx versions, removed here.
04Common use cases
- Putting a Node.js, Python or Go app on port 3000 behind nginx with the right forwarding headers so the app logs real client IPs
- Hosting a React or Vue build where deep links like /settings/profile must load index.html instead of a 404
- Moving a site to HTTPS with a port 80 redirect, TLS 1.2/1.3 and an HSTS header
- Retiring an old domain with a 301 to the new one
- Spreading traffic across two or three app instances with least_conn or sticky ip_hash sessions
- Adding a per-IP rate limit and a larger upload limit for an API that accepts file uploads
- Proxying a chat or live-update app that needs WebSocket upgrade headers
05Tips
- nginx before 1.25.1 doesn't know the http2 directive. On older versions delete that line and use listen 443 ssl http2; instead.
- add_header lines in a location block replace all the ones inherited from the server block. If you add headers to a location, repeat your security headers there.
- For a redirect that keeps paths, set the Redirect URL to something like https://new.example.com$request_uri.
- limit_req_zone has to live in the http context. The generated file works because conf.d files are included inside http, but don't paste it inside another server block.
- Static Asset Caching only changes the Static Site and Single Page App configs. For a reverse proxy, caching headers come from your app.
06Related concepts
Server blocks, try_files, Upstream, proxy_pass.
Frequently Asked Questions
What is Nginx Config Generator?
Nginx Config Generator is a free, browser-based developer tool on AIDToolStack. Generate nginx server blocks for reverse proxy, SPA, static sites, and more. It requires no installation or sign-up and works entirely in your browser.
Is Nginx Config Generator free to use?
Yes. No sign-up, no fees and no usage cap.
Does Nginx Config Generator store my data?
No. It runs in your browser; nothing is uploaded.