Nginx Config Generator

Config lines—
Mode—
Main port—
SSL—

How Nginx Config Generator is calculated: One server block per site: listen, server_name, root or proxy_pass, plus an HTTP-to-HTTPS redirect block when SSL is on.

What is an Nginx config generator?

An Nginx config generator writes the server block you need to host a website with Nginx, the web server that runs a large share of the busiest sites on the internet. You type your domain, pick a port, set the document root, and the tool writes the configuration in the right order, ready to paste into your nginx.conf file or a site file under sites-available. The default output is a 10-line static-site block for example.com on port 80.

A server block is the unit of configuration in Nginx. It says which domain the block answers for, which port it listens on, where the files live, and what to do with each request. Get one line wrong and Nginx either refuses to start or serves the wrong site, so a generator that writes the lines in the right order saves real debugging time. A Dockerfile generator is the companion tool when the site runs inside a container, and a SSL checker confirms the certificate is actually working once the site is live.

This generator covers the two setups most people need: a static site served from a folder, and a reverse proxy in front of an app running on another port. It also handles the HTTPS case, writing both the port 443 block and the small port 80 block that redirects visitors to the secure address. Everything runs in your browser, and nothing you type is uploaded anywhere.

The output is a starting point, not a finished production file. It uses the standard paths for certificates and the standard headers for proxies, and the article explains what to check before you use it on a live server. If your setup is unusual, read the last sections before pasting anything.

How an Nginx config works

The config is a server block: a group of directives inside curly braces. The listen directive sets the port, server_name sets the domain, and root sets the folder that holds the website files. The index directive names the file served when a visitor asks for a folder, usually index.html. The location block then says what to do with requests: for a static site, try_files looks for the exact file, then the folder, then returns a 404.

The reverse proxy form replaces root with proxy_pass. Instead of reading files from disk, Nginx forwards each request to your app, for example an app on http://127.0.0.1:3000, and passes the result back to the visitor. The two proxy_set_header lines matter: without them your app sees every visitor as coming from 127.0.0.1, and it cannot tell visitors apart or build correct links. A DNS checker is useful at this stage, because a proxy that points at the wrong host fails in ways that look like an app bug.

When SSL is on, the generator writes two server blocks. The first listens on port 443 with ssl_certificate and ssl_certificate_key pointing at the certificate files for your domain. The second listens on port 80 and does nothing but return a 301 redirect to the https address, so nobody stays on the plain version by accident. With SSL off and gzip on, the default static config is 10 lines; with SSL on it is 17 lines, because of the certificate lines and the redirect block.

Gzip is on by default because it shrinks text files before they travel over the network, which makes pages load faster. It only helps text, though: images and video are already compressed, and gzipping them wastes CPU. The generator writes one gzip on line, and your server applies it to text responses.

The domain and document root explained

The domain is the name visitors type, and server_name must match it exactly. If you type example.com but visitors arrive at www.example.com, Nginx will not match this block and will serve its default site instead. That is the single most common cause of a new Nginx site showing the wrong page, and the fix is to list every name the site answers to, separated by spaces, in server_name.

The document root is the folder on the server that holds the website files. The default is /var/www/html, the standard folder on Ubuntu and Debian. If your files live somewhere else, change it to match: the root in the config must be the folder that actually contains index.html, not its parent and not a subfolder. A URL parser can help you check the shape of the address your visitors will use, but the folder itself is a server-side fact only you can confirm.

The port is 80 for plain HTTP and 443 for HTTPS. If another service already uses port 80, Nginx will fail to start with an address-in-use error, and the fix is to stop the other service or move Nginx to a different port. Ports below 1024 need administrator rights on Linux, which is why Nginx is normally started as root and then drops to a worker user.

The proxy target is only used when you fill it in. Leave it empty and you get a static site; type an address like http://127.0.0.1:3000 and the root and index lines disappear, because a proxied app serves its own files. The proxy address must include the scheme and the port, and it must be reachable from the Nginx server itself.

A worked example: static site, then HTTPS, then proxy

Start with the page defaults: domain example.com, port 80, root /var/www/html, SSL off, gzip on, no proxy. The generator writes a 10-line config: server, listen 80, server_name example.com, root, index, gzip on, a location block with try_files, and the closing braces. The results read Config lines: 10, Mode: Static site, Main port: 80, SSL: Off. That is the whole file for a plain static site.

Now tick the SSL box and press the button again. The config grows to 17 lines: the main block now listens on 443 ssl, gains the two ssl_certificate lines, keeps gzip on, and a second 5-line server block appears that listens on 80 and returns a 301 redirect to the https address. The results read Config lines: 17, Main port: 443, SSL: On. Before this works for real, the certificate files must exist at the paths shown, or Nginx will refuse to start.

Now turn SSL off again and type http://127.0.0.1:3000 into the proxy box. The config becomes 10 lines: listen 80, server_name, gzip on, and a location block with proxy_pass plus the two proxy_set_header lines. The root and index lines are gone, because the app behind the proxy serves the files. The results read Config lines: 10, Mode: Reverse proxy, Main port: 80, SSL: Off.

Compare the three outputs side by side and the pattern is clear: the listen and server_name lines never change shape, only the values; the location block is where the mode shows up; and SSL adds a whole second block. That is all an Nginx config really is: one block per site, plus a redirect block when you want HTTPS.

Who uses an Nginx config generator, and why

Developers setting up a first server are the main users. Nginx is powerful but its config syntax is unforgiving, and a missing semicolon or a brace in the wrong place stops the whole server. A generator writes the skeleton correctly, so the first attempt usually works, and the developer can focus on the app instead of the config file.

Students learning servers are the second group. A config generator shows the shape of a working file without a wall of documentation, and changing one option at a time shows exactly which lines that option controls. It is a faster way to learn than copying a full example from a tutorial and guessing which parts matter.

Small teams shipping a side project are the third group. They need a static site or a proxy in front of a Node or Python app, and they need it today, not after reading the Nginx manual. The generated file is short enough to read in full, which matters: a config you have read is one you can debug. A cron expression generator covers the other half of the same job, scheduling the jobs that keep the server healthy.

The tool is also useful as a checklist. If your hand-written config behaves oddly, generate the same setup here and compare the two line by line. The differences are usually the bug: a missing try_files, a proxy without the Host header, or an SSL block without its redirect.

Nginx config generator vs writing it by hand

Writing the config by hand gives you full control: every directive Nginx supports is available, including caching, rate limiting, and load balancing across several app servers. The generator covers the common cases only, and anything exotic still needs hand-written lines. That is a fair trade for a first setup, and a bad one for a complex one.

The generator wins on correctness for the common cases. It never forgets a semicolon, never mismatches a brace, and never writes the redirect block without the main block. Hand-written configs fail on exactly those small things, usually at the worst moment, right after a deploy. Use the generator for the skeleton, then add your special lines by hand on top of it.

The other comparison is with a control panel. Panels hide the config entirely, which is convenient until something breaks and you cannot see what the panel wrote. A generated file is plain text you can read, copy, and version-control, which is the middle ground: faster than hand-writing, more transparent than a panel.

Whichever route you take, the same rule applies: test the config before reloading Nginx. Run nginx -t to check the syntax, then reload. A bad config loaded live can take every site on the server down at once, and the test takes less than a second.

Common Nginx mistakes

The first mistake is a server_name that does not match the domain visitors use. If the site answers for example.com but visitors type www.example.com, Nginx serves the default site. List every name the site answers to, or add a redirect from one to the other.

The second mistake is a wrong document root. The root must be the folder containing index.html. Point it at the parent folder and every request 404s; point it at a subfolder and the site loads but its assets break. Check the folder on the server, not in your head.

The third mistake is forgetting nginx -t before reloading. A syntax error in one site file stops Nginx from starting at all, which takes down every site on the server. Test first, reload second, and keep a backup of the last working config.

The fourth mistake is a proxy without the Host header. Without proxy_set_header Host $host, your app sees every request as coming to 127.0.0.1, which breaks redirects, cookies, and anything that builds links from the request. The generator includes both header lines for exactly this reason.

The fifth mistake is an SSL block pointing at certificate files that do not exist yet. Nginx refuses to start if the certificate path is wrong, so get the certificate first with a tool like Certbot, then write the config, then test and reload.

How to use this Nginx config generator

Type your domain, check the port, and set the document root to the folder that holds your site. Leave the proxy box empty for a static site, or type your app address for a reverse proxy. Tick SSL only if you already have a certificate for the domain, and leave gzip on unless you have a reason to turn it off. Press Generate Nginx Config and the file appears in the box below.

Copy the output into a file on your server, usually /etc/nginx/sites-available/your-domain, then link it into sites-enabled and run nginx -t to check the syntax. If the test passes, reload Nginx with systemctl reload nginx. If the test fails, read the error: it names the file and the line number, and the fix is usually a typo in a path you typed.

Everything runs in your browser. Nothing you type is uploaded, stored, or shared, and the config never leaves your device. You can generate as many configs as you like without signing up.

Treat the output as a starting point and review it before use on a live server, especially the certificate paths and the proxy address. The generator cannot see your server, so it cannot check that the folders and the app actually exist where the config says they do.

Frequently Asked Questions

A server block is a group of settings inside curly braces that tells Nginx how to handle one website: which domain and port it answers on, where the files live, and what to do with each request. One block usually equals one site. The generator writes one block for your site, plus a second small block that redirects HTTP to HTTPS when SSL is on.

On Ubuntu and Debian, save it as a file under /etc/nginx/sites-available/, then create a symbolic link to it from /etc/nginx/sites-enabled/ and run nginx -t followed by systemctl reload nginx. On other systems the path differs, but the file content is the same. Always run nginx -t before reloading, so a typo cannot take the server down.

Yes. The SSL config points at a certificate and a private key for your domain, and Nginx will not start if those files are missing. Get a free certificate from Let's Encrypt with Certbot first, check the file paths it creates, and only then tick the SSL box. The generator uses the standard paths /etc/ssl/certs/ and /etc/ssl/private/.

Root tells Nginx to serve files from a folder on disk, which is how a static site works. Proxy_pass tells Nginx to forward each request to another program, such as a Node.js or Python app, and pass the answer back. Use root for static sites and proxy_pass when an app generates the pages. The generator switches between them automatically.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.