Skip to content
UniKit

Nginx config generator

Generate an nginx server block: pick static hosting, SPA history fallback, reverse proxy, load balancing, HTTPS redirect, caching with gzip or WebSocket upgrade, and copy an indented config ready for conf.d.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Scenarios and settings

Scenarios

Notes

nginx config

Save it as /etc/nginx/conf.d/<domain>.conf, run nginx -t and reload.

# Generated by UniKit — drop it into /etc/nginx/conf.d/ or sites-enabled/
# Scenarios: static + spa

server {
    server_name example.com;

    listen 80;

    root /var/www/html;
    index index.html;

    client_max_body_size 10m;

    # static files with history fallback
    location / {
        try_files $uri $uri/ /index.html;
    }

    # security headers
    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;
}

Statistics

Server blocks1
Locations1
Lines22

What this tool does

  • Deploying a frontend: select static hosting plus SPA history fallback, enter the document root, and get a server block with try_files so deep links survive a refresh.
  • Putting a proxy in front of an API: enter the proxy target and the four headers (Host, X-Real-IP, X-Forwarded-For, X-Forwarded-Proto) are filled in for you.
  • Going HTTPS: the HTTPS scenario emits both the 301 redirect server on port 80 and the 443 ssl server, with certificate paths pre-filled from the Let's Encrypt layout.
  • Adding compression and caching to an old config: pick caching and gzip to get expires plus immutable headers for assets and gzip for text types.

Example

Input

Scenarios: static site + SPA history fallback; server_name example.com; port 80; root /var/www/html; index index.html

Output

# Generated by UniKit — drop it into /etc/nginx/conf.d/ or sites-enabled/
# Scenarios: static + spa

server {
    server_name example.com;

    listen 80;

    root /var/www/html;
    index index.html;

    client_max_body_size 10m;

    # static files with history fallback
    location / {
        try_files $uri $uri/ /index.html;
    }

    # security headers
    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;
}

Indentation is always four spaces; with HTTPS selected a second server block is added that only performs the 301 redirect.

Frequently asked questions

Where do I put the generated config?

Save it to /etc/nginx/conf.d/<domain>.conf or under sites-enabled/, run nginx -t to check the syntax, then nginx -s reload. If you selected WebSocket, keep the map directive at http level rather than inside the server block.

What is the difference between static hosting and SPA fallback?

Static hosting uses try_files $uri $uri/ =404 and returns 404 for unknown paths. The SPA fallback uses try_files $uri $uri/ /index.html, handing unknown paths to the client router so refreshing /user/1 keeps working. Only that single line inside location / changes.

Can I select reverse proxy and load balancing together?

Yes, but load balancing wins: proxy_pass points at the upstream name instead of a single address and a note is shown. With reverse proxy alone, proxy_pass uses the address you typed.

How do I write weight in an upstream?

One server per line as host:port with optional parameters, for example 127.0.0.1:3001 weight=3. weight, max_fails, fail_timeout, backup and down are accepted; anything else is reported as a format error.

What happens if I set cache days to 0?

You get expires 0d and max-age=0, which makes browsers revalidate every asset — handy while debugging. In production 7 to 30 days is typical, paired with hashed asset filenames.

Keywords:nginxnginx configserver blockreverse proxyload balancingnginx 配置反向代理负载均衡https 跳转gzip

Related tools