Quick answer: Install Nginx, PHP-FPM and MariaDB, then create a server block that routes requests through try_files to index.php and passes PHP to the FPM socket. Nginx serves WordPress faster than default Apache setups and pairs naturally with FastCGI caching later.
Overview
Nginx is the most popular web server for self-hosted WordPress: light on memory, excellent at static files and straightforward to configure. WordPress needs exactly one special rule — pretty permalinks via try_files. This article gives a production-ready server block for Ubuntu 22.04/24.04.
Before you start
- Nginx installed, plus PHP-FPM and MariaDB.
- WordPress files in place and a database created (install guide).
- Your domain’s A record pointed at the VPS.
Step-by-step guide
- Create
/etc/nginx/sites-available/example.com:server { listen 80; server_name example.com www.example.com; root /var/www/example.com; index index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.3-fpm.sock; } location ~* \.(css|js|jpg|jpeg|png|gif|webp|svg|woff2)$ { expires 30d; access_log off; } location = /xmlrpc.php { deny all; } location ~ /\.(?!well-known) { deny all; } client_max_body_size 64m; } - Enable and reload:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx - Open the site, finish the WordPress installer if you haven’t, and set permalinks to “Post name”.
- Add HTTPS next — SSL for WordPress — and consider FastCGI page caching once the site is live (speed guide).
Common issues
- 404 on every page except the front page: the
try_filesline is missing — permalinks need it. - 502 Bad Gateway: PHP-FPM socket path doesn’t match your PHP version — check
ls /run/php/. - Large uploads fail: raise
client_max_body_sizein Nginx ANDupload_max_filesizein PHP.
When to contact support
Platform-level problems (VPS unreachable, disk or network faults) are for the support team; web-server configuration on an unmanaged VPS is yours, and this guide plus nginx -t output usually pinpoints the issue.
Frequently asked questions
Why does WordPress need try_files in Nginx?
Pretty permalinks are virtual URLs with no matching file on disk; try_files sends them to index.php so WordPress can route the request — without it every inner page returns 404.
Is Nginx better than Apache for WordPress?
Nginx typically uses less memory and handles static files and many concurrent connections better; Apache offers .htaccess flexibility. On a small VPS, Nginx + PHP-FPM is the common recommendation.
Why block xmlrpc.php in the server block?
xmlrpc.php is a frequent brute-force and DDoS amplification target; if you do not use the Jetpack app or remote publishing, denying it at the web server removes the attack surface cheaply.
Related articles
- How to install WordPress on a VPS
- How to configure SSL for WordPress
- How to improve WordPress speed on a VPS
- How to install WordPress with OpenLiteSpeed
Ready to get started? Order a WordPress VPS at Cloud2Y →
