WordPress Nginx config generator
Pick the rules you want and get a ready Nginx server block for WordPress. It starts from the WordPress handbook and adds only what you tick, with a note on every rule.
This is for a server you control, such as a VPS. Many managed hosts do not let you edit Nginx. Everything runs in your browser. Nothing you type is sent anywhere.
Your config
Server block. Goes in /etc/nginx/sites-available/example.com.conf (Debian and Ubuntu convention).
# Nginx server block for WordPress. Made with the AllWPCare Nginx config generator.
# Save it as /etc/nginx/sites-available/example.com.conf (the Debian and Ubuntu convention, other systems differ).
# Test before you reload: sudo nginx -t. If the test fails, nothing has changed.
# The WordPress site.
server {
listen 80;
server_name example.com www.example.com;
# The folder that holds wp-config.php, wp-content and wp-admin (or the folder above it, for a WordPress in a sub-folder).
root /var/www/example.com/public;
index index.php;
# Standard favicon and robots.txt. If the file is missing, WordPress answers instead, so its own robots.txt keeps working.
location = /favicon.ico {
access_log off;
try_files $uri /index.php?$args;
}
location = /robots.txt {
access_log off;
try_files $uri /index.php?$args;
}
# Pretty permalinks: a real file or folder is served as it is, anything else goes to WordPress.
location / {
try_files $uri $uri/ /index.php?$args;
}
# PHP files go to PHP-FPM. try_files makes sure the file exists before PHP sees it.
location ~ \.php$ {
try_files $uri =404;
include fastcgi.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
}
Put it live safely
- Back up first. If the file already exists, copy it:
sudo cp /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-available/example.com.conf.bak - Save the new text as
/etc/nginx/sites-available/example.com.conf. That folder is the Debian and Ubuntu convention. Other systems differ, often/etc/nginx/conf.d/. On Debian and Ubuntu, a new site also needs a link:sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/ - Test it:
sudo nginx -t. This checks the syntax and does not change the running server. Only go on if it says the test is successful. If it shows an error, nothing has changed. Fix the line it names, or put your backup back. - Reload:
sudo systemctl reload nginx - Open your home page, a post, your login page and the media library, and check each one loads.
- To undo, put the backup file back, run
sudo nginx -tagain, then reload.
How it works
You get one server block per name that needs one, with a comment on each rule. Anything that belongs somewhere else, such as the login limit line for the http block, comes as a separate labelled part.
What the file always has
try_files $uri $uri/ /index.php?$args;from the WordPress handbook. It serves a real file or folder, and sends everything else to WordPress, so links like/about/work.- A PHP location that passes
.phpfiles to PHP-FPM, and only when the file exists. /favicon.icoand/robots.txtlocations. If the file is missing, WordPress answers, so its own robots.txt keeps working.
What it does not do
- It does not read or change your server. You copy the result yourself.
- It does not accept your own rules. Free text in a config can break it or open a hole.
- It does not set up PHP-FPM, install a certificate or turn on HTTP/2. Those depend on your server.
- It does not write caching for a cache plugin or a page cache. Use the one your site already has.
If you cannot edit Nginx
On managed hosting, some of this can be done inside WordPress instead. The WellTend Site and Admin Toolkit has modules for browser security headers, turning off XML-RPC and limiting login attempts. They are a different tool from Nginx rules, and they only run when WordPress runs.
FAQ
Where does this file go?
On Debian and Ubuntu, save it as /etc/nginx/sites-available/yourdomain.conf and link it into /etc/nginx/sites-enabled/. Other systems often use /etc/nginx/conf.d/ instead. Run sudo nginx -t before you reload. If the test fails, nothing has changed.
I am on managed WordPress hosting. Will this work?
Usually not. Most managed hosts do not let you edit the Nginx config. This is for a VPS or a server you control. Ask your host which of these settings they let you change, or use a plugin that does the same job inside WordPress.
I use Apache. Is there a version for me?
Yes. Nginx ignores .htaccess files, and Apache ignores this file. Use the .htaccess generator instead.
Why are the headers not inside each location?
Because of how add_header is passed down. Nginx only passes the add_header lines of the level above to a block that has none of its own. One add_header inside a location silently drops all the others there. This file sets the headers once, at server level, and has no add_header inside a location. If you add your own, copy the header lines into that location too.
Why is there no rule for folder listings?
Nginx does not list a folder's files unless autoindex on is set, and it is off by default. There is nothing to add. Check that no other config file turns it on.
Why is the login limit a second snippet?
limit_req_zone is only allowed in the http block, outside any server block. The rule that uses it goes in the server block. On Debian and Ubuntu, nginx.conf includes sites-enabled inside the http block, so the top of your site file works too.
Does the file check that my settings are right?
It checks that your names and paths are safe to write, and that the result is well formed. It cannot know your PHP socket name or your certificate files. sudo nginx -t on your server is the real test, and it tells you before anything changes.
Is a site with these options "secure"?
No. No file makes a site secure. Each option says what it does not stop. For the bigger picture, see the hardening guide below.