VirtualMin WordPress Nginx Permalinks 404 [Solved]

On default virtualmin install with LEMP, running nginx, the permalinks for WordPress don’t work properly and give a 404 error. This article explains how to fix this issue.

Why WordPress permalinks show 404 in virtualmin fresh install?

The reason is nginx configuration file. The configuration for wordpress needs some extra lines of code and logic to be added to the configuration file.

The file is not nginx.conf, it’s your-domain.conf file (found in /etc/nginx/sites-availble/ )

How to fix 404 error on links in wordpress on virtualmin running nginx

We need to modify the nginx configuration file of our domain.

Edit your domains nginx.conf file by first going to the directory and then confirming the name of your domains file (you can directly edit if you’re sure about the file name).

cd /etc/nginx/sites-available/
ls
nano domain-name.com.conf

Nano will open the file in editor and then you can modify it.

404 not found nginx virtualmin wordpress

Once you’ll open file editor via nano, you might see something like this:

server {
    server_name nabtron.com www.nabtron.com;
    listen 12.34.56.78;
    root /home/nabtron/public_html;
    index index.html index.htm index.php;
    access_log /var/log/virtualmin/nabtron.com_access_log;
    error_log /var/log/virtualmin/nabtron.com_error_log;
    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    fastcgi_param SCRIPT_FILENAME /home/nabtron/public_html$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT /home/nabtron/public_html;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;
    fastcgi_param HTTPS $https;

    location ~ .php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/php-nginx/12345678.sock/socket;
    }
    listen 45.64.105.90:443 ssl;
    ssl_certificate /home/nabtron/ssl.cert;
    ssl_certificate_key /home/nabtron/ssl.key;
    rewrite_log off;
}

Please note, do not copy the whole block of code above, it’s customized to another domain and server at various points including fastcgi_pass socket.

In this file, just above the location ~ .php$ { block, add this code:

    location / { 
        index index.php index.html index.htm; 
        try_files $uri $uri/ /index.php$is_args$args;
    }

If you’re running wordpress in a subdirectory of your domain, then you might change /index.php$is_args$args; to /folder-name/index.php$is_args$args;.

Save the file and then restart nginx by:

service nginx restart

Don’t forget to clear local, cdn and browser cache before checking.

If everything goes without any errors, you’ll now be having no 404 errors for subpages for your wordpress on nginx in virtualmin LEMP environment.

Please let me know if you still have any difficulty or query.

6 comments on “VirtualMin WordPress Nginx Permalinks 404 [Solved]

  1. After much futile searching on how to do this (this is day one of using nginx for me), I found this page.

    I’m so grateful, I may have to name my first child after you! ;-)

Leave a Reply

Your email address will not be published.