Nginx Config Generator
Answer a few questions and get a clean Nginx server block you can drop into your server. It covers PHP-FPM, WordPress, static sites, single-page apps and reverse proxies, with HTTPS done properly.
- Free
- No sign-up
- Runs in your browser
Everything runs in your browser. What you type here is never uploaded, stored or sent anywhere.
What is an Nginx server block?
Nginx is one of the most popular web servers. It reads its settings from configuration files, and each website gets a "server block": a short section that says which domain it answers for, where the files live, how to handle PHP, and what to do with HTTPS. Writing one by hand is easy to get slightly wrong, and a small mistake can mean a broken site or a security gap.
This generator writes the server block for you using patterns that work in production. It uses try_files the safe way for PHP, redirects HTTP to HTTPS, keeps one canonical hostname, and avoids a classic Nginx trap: add_header lines in a location block silently cancel the ones you set at the server level, so the generated caching rules deliberately avoid it.
Running Apache instead? Use the .htaccess Generator. If you are moving a site, you may also want to set up scheduled backups with the Cron Expression Generator.
How to create and apply an Nginx config
- Enter your domain and choose the type of site: PHP, WordPress, Static, Single-page app or Reverse proxy.
- Check the web root and, for PHP sites, the PHP-FPM socket. Run
ls /run/php/on your server if you are not sure of the exact name. - Turn on the extras you want: HTTPS, compression, caching, security headers.
- Save the output as
/etc/nginx/sites-available/yourdomain.comand link it intosites-enabled. - Run
sudo nginx -tto test the syntax, thensudo systemctl reload nginxto apply it.
Typical setups
- A WordPress site on a VPS (DigitalOcean, Hetzner, AWS Lightsail) with PHP-FPM.
- A Laravel or custom PHP app where every request goes through
index.php. - A React, Vue or Angular build served as static files with client-side routing.
- Putting Nginx in front of a Node.js, Python or Go app running on a local port.
- Redirecting
wwwto the bare domain (or the other way round) so search engines see one site.
Frequently asked questions
Where do I put the generated Nginx config?
On Debian and Ubuntu, save it as /etc/nginx/sites-available/yourdomain.com and run sudo ln -s to link it into /etc/nginx/sites-enabled/. On other systems, put it in /etc/nginx/conf.d/yourdomain.com.conf. Then run sudo nginx -t and reload Nginx.
Nginx says the certificate file does not exist. What do I do?
The certificate has to exist before Nginx will accept an HTTPS block. Generate the config with HTTPS off first, enable the site, then run certbot certonly --webroot with your web root and domain. After the certificate is issued, generate the config again with HTTPS on.
What is the difference between listen 443 ssl http2 and http2 on?
From Nginx 1.25.1 the http2 parameter on the listen line is deprecated and replaced by a separate http2 on; directive. Choose Nginx 1.25.1 or newer if nginx -v shows that version or higher, otherwise choose the older style.
Why do my security headers disappear on image or CSS files?
In Nginx, if a location block contains any add_header line, it ignores all add_header lines from the level above. The generated caching block uses expires only, so your headers stay in place. Keep that in mind when you add your own location blocks.
How do I find my PHP-FPM socket?
Run ls /run/php/ on the server. You will see something like php8.3-fpm.sock. Use unix:/run/php/php8.3-fpm.sock here. Some setups use a TCP address like 127.0.0.1:9000 instead.
Is the config safe to use as it is?
It follows common best practice, but every server is different. Test it on a staging server or run nginx -t first, keep a backup of your old config, and review anything you do not recognise.
