EN
My tools

Nginx Config Generator (server block)

Build an nginx server block: static site, SPA, PHP-FPM or reverse proxy, with HTTPS from Let’s Encrypt, redirects, HTTP/2, gzip, caching, headers and WebSockets.

The first name is the main one; others redirect to it if you choose below.
nginx config
Test and reload
sudo nginx -t && sudo systemctl reload nginx
Server blocks
3
Location blocks
4
Syntax check
Braces balanced; every directive ends with ;

Get the certificate before reloading, or nginx -t fails on the missing files: create /var/www/letsencrypt, start with the port-80 block only, then run certbot certonly --webroot -w /var/www/letsencrypt -d example.com -d www.example.com. Wildcard names need a DNS challenge instead.

Static-asset caching is left to your app in reverse-proxy mode; set Cache-Control headers there.

Save the file as /etc/nginx/sites-available/example.com (Debian/Ubuntu, then link it into sites-enabled) or /etc/nginx/conf.d/example.com.conf, then test and reload.

My tools →
Advertisement

nginx serves most of the web, but its configuration is easy to get subtly wrong: a missing semicolon, an HTTPS redirect loop, or security headers that silently disappear inside a location block. This generator writes a complete, commented server block for a static site, a single-page app, a PHP-FPM site or a reverse proxy to an app on another port, with Let’s Encrypt HTTPS, canonical-host redirects, HTTP/2, gzip, asset caching, security headers, WebSockets and optional rate limiting.

How to use this tool

  1. Enter the domain names (the first is the main one) and choose the site type.
  2. Fill in the web root, the app address or the PHP-FPM socket.
  3. Tick HTTPS, redirects and the extras you want.
  4. Save the file, get the certificate, then run nginx -t and reload.

Formula

HTTPS layout: server :80 (ACME challenge + 301 to https) → server :443 for the extra names (301 to the main name) → server :443 for the main name with the site configuration.

try_files decides what is served: $uri $uri/ =404 for static files, /index.html as the fallback for single-page apps, /index.php?$query_string for PHP front controllers. add_header lines in the server block are not inherited by a location that has its own add_header, so the generated locations avoid add_header.

Example

For example.com and www.example.com as a reverse proxy to http://127.0.0.1:3000 with HTTPS, the output has 3 server blocks — the port-80 redirect, www → example.com on 443, and the main site — and its main location contains proxy_pass http://127.0.0.1:3000; with the Host, X-Forwarded and WebSocket upgrade headers.

Frequently asked questions

Where does the map block go?

map and limit_req_zone belong in the http context. Files in /etc/nginx/conf.d/ and sites-enabled/ are included inside http, so the generated file can be saved there as it is.

Why "http2 on;" instead of "listen 443 ssl http2"?

nginx 1.25.1 introduced the separate http2 directive and deprecated the listen parameter. Untick the newer-syntax option for older versions such as the 1.18 or 1.22 packages in some distributions.

Should I enable HSTS straight away?

No. Once browsers see HSTS they refuse plain HTTP for the whole max-age. Turn it on after HTTPS works everywhere, and add includeSubDomains only when every subdomain is ready.

Sources

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). Nginx Config Generator (server block). https://kakao.mobile/tools/nginx-config-generator/

MLA

“Nginx Config Generator (server block).” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/nginx-config-generator/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement