Skip to main content
Dev · 283 tools

Nginx Config Generator

Generates example Nginx server block configurations for learning and as a starting point

Nginx ConfigExample — click Generate for yours
# single-page app for example.io (example server block; include it inside http { } and adjust names, paths and ports) server { listen 80; server_name www.example.io; return 301 https://$host$request_uri; } server { listen 443 ssl; http2 on; server_name www.example.io; ssl_certificate /etc/letsencrypt/live/www.example.io/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.example.io/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; root /usr/share/nginx/example.io/current/public; index index.html; access_log /srv/logs/nginx/www.example.io.ssl.access.log; error_log /srv/logs/nginx/www.example.io.ssl.error.log notice; location / { try_files $uri $uri/ /index.html; } location = /index.html { add_header Cache-Control "no-cache"; } location /uploads/ { alias /srv/http/example.io-storage/; autoindex off; } add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header Referrer-Policy "same-origin" always; location = /health { access_log off; default_type text/plain; return 200 "up"; } }

Generated 104 words · 1,132 characters

See 3 examples
  • Example 1
    # single-page app for example.io (example server block; include it inside http { } and adjust names, paths and ports)
    server {
      listen 80;
      server_name www.example.io;
      return 301 https://$host$request_uri;
    }
    
    server {
      listen 443 ssl;
      http2 on;
      server_name www.example.io;
      ssl_certificate     /etc/letsencrypt/live/www.example.io/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/www.example.io/privkey.pem;
      ssl_protocols TLSv1.2 TLSv1.3;
      root /usr/share/nginx/example.io/current/public;
      index index.html;
      access_log /srv/logs/nginx/www.example.io.ssl.access.log;
      error_log  /srv/logs/nginx/www.example.io.ssl.error.log notice;
    
      location / {
        try_files $uri $uri/ /index.html;
      }
    
      location = /index.html {
        add_header Cache-Control "no-cache";
      }
    
      location /uploads/ {
        alias /srv/http/example.io-storage/;
        autoindex off;
      }
    
      add_header X-Content-Type-Options "nosniff" always;
      add_header X-Frame-Options "SAMEORIGIN" always;
      add_header Referrer-Policy "same-origin" always;
    
      location = /health {
        access_log off;
        default_type text/plain;
        return 200 "up";
      }
    }
  • Example 2
    # maintenance for quarry.cloud (example server block; include it inside http { } and adjust names, paths and ports)
    server {
      listen 80 default_server;
      server_name quarry.cloud www.quarry.cloud;
      root /srv/www/quarry.cloud-maintenance;
    
      location / {
        return 503;
      }
    
      error_page 503 /down.html;
      location = /down.html {
        internal;
      }
      add_header Retry-After 1800 always;
    }
  • Example 3
    # php-fpm for mosaic.dev (example server block; include it inside http { } and adjust names, paths and ports)
    server {
      listen 80;
      server_name mosaic.dev www.mosaic.dev;
      root /var/www/mosaic.dev/current/public;
      index index.php index.html;
      access_log /srv/logs/nginx/mosaic.dev.access.log;
      error_log  /srv/logs/nginx/mosaic.dev.error.log warn;
      client_max_body_size 16m;
    
      location / {
        try_files $uri $uri/ /index.php?$args;
      }
    
      location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm/www.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    
      add_header X-Content-Type-Options "nosniff" always;
      add_header X-Frame-Options "DENY" always;
      add_header Referrer-Policy "same-origin" always;
    
      location ~ /\.(?!well-known) { deny all; }
    
      location = /favicon.ico { log_not_found off; access_log off; }
    }

About this generator

Nginx configuration syntax trips up developers who do not work with it daily: the directive names, block nesting, and subtle differences between a static site, a reverse proxy, and a redirect are easy to misremember. This generator produces example Nginx server blocks for common setups so you have a correct, working template to adapt rather than a blank file. The config type dropdown selects what to generate, or random picks from eleven common setups (static site, reverse proxy, redirect, load balancer, PHP-FPM, WordPress, API gateway, WebSocket proxy, maintenance page, HTTPS static site and single-page app). Static site produces a server block that listens on port 80, sets the document root, and uses try_files to serve files or return a 404. Reverse proxy produces an upstream pointing at 127.0.0.1 on a common application port (such as 3000, 5173, 8000 or 8080) plus a server block with proxy_pass and the usual Host, X-Real-IP, X-Forwarded-For and X-Forwarded-Proto headers. Redirect produces one of four patterns: www to the bare domain, HTTP to HTTPS, an old domain to a new one, or a temporary redirect for one section, each with a matching status code (301 or 308 for permanent moves, 302 or 307 for temporary ones). Many results also add one to three optional extras, such as static-asset caching, gzip, security headers, a health-check endpoint, or custom error pages. Treat the output as a learning scaffold and a starting point: adapt the domain name, document root path, and proxy port to your actual setup, add a TLS server block for HTTPS, and run nginx -t to validate the config before reloading. The generated block is a correct minimum for each type but is not a finished production configuration.

How to use

  1. Choose a config type — static site, reverse proxy, or redirect.
  2. Click Generate to produce an example server block.
  3. Adapt the domain, paths, and ports to your setup.
  4. Add TLS and test the config before deploying it.

Use Cases

  • •Learning Nginx server block syntax
  • •Starting a static-site, proxy, or redirect config
  • •Documentation and tutorial examples
  • •Reminding yourself of directive structure
  • •Prototyping a configuration before refining it

Tips

  • →Run nginx -t to test a config before reloading the server.
  • →Add HTTPS with a TLS certificate before going to production.
  • →For a reverse proxy, match the proxy_pass port to your app.
  • →Treat generated configs as scaffolding, not a finished setup.

FAQ

what is an nginx server block

A server block is the section of an Nginx configuration that defines how to handle requests for a particular domain or port — what to listen on, which server name to match, where files live, and how to route requests. It is the core unit you assemble an Nginx setup from.

is this config production-ready

It is a correct, realistic starting point rather than a finished production config. You should adapt the domain, paths, and ports, add TLS and security headers, and test it before deploying. Treat it as a learning aid and a scaffold to build on.

what is a reverse proxy config for

A reverse proxy server block forwards incoming requests to an application running on another port or host — for example a Node app on port 3000 — while Nginx handles the public-facing connection. It is a very common pattern for serving web apps behind Nginx.

what ports does the reverse proxy config use

The reverse proxy upstream points at 127.0.0.1 on a randomly chosen common development port, such as 3000, 4000, 5000, 5173, 8000, 8080 or 9000. These are typical defaults for Node.js, Vite, Python and other application servers. Change the port in the upstream block to match the port your actual application binds to.

You might also like

Popular tools from other categories that share themes with this one.