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

Step-by-step guide

  1. 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;
    }
  2. Enable and reload:
    sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
    sudo nginx -t && sudo systemctl reload nginx
  3. Open the site, finish the WordPress installer if you haven’t, and set permalinks to “Post name”.
  4. 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_files line 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_size in Nginx AND upload_max_filesize in 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

Ready to get started? Order a WordPress VPS at Cloud2Y →

Was this answer helpful? 0 Users Found This Useful (0 Votes)