WordPress Permalink Problem with Nginx webserver

I recently rebuilt my VPS with centos 6, virtualmin and Nginx web server.

I am unable to make use of WordPress Permalinks. Default permalink is working but when I activate a custom permalink the following error is displayed

404 Not Found nginx/1.0.9


nginx/1.0.9

I googled and installed a compatibility plugin but I am getting the same error.

I don’t want to do anything which will harm the server. So I require a possible correct solution for this.

Please help

Regards,
Anand

Hello there,

I came upon this thread while searching for this, too, but then I remembered that I already did it on another Wordpress site.

So, to do fix this you need to edit the domain’s Nginx configuration file. If you are a beginner, I wouldn’t suggest doing it because you can break stuff.

For example, your domain is mywordpress.com – what you need to do is login via SSH and open the file /etc/nginx/sites-available/mywordpress.com, and between:

    fastcgi_param HTTPS $https;
    ...
    location ~ \.php$ {

add the following:

    fastcgi_hide_header X-Powered-By;

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
            set $host_without_www $1;
            rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }

    # unless the request is for a valid file, send to bootstrap
    if (!-e $request_filename)
    {
            rewrite ^(.+)$ /index.php?q=$1 last;
    }

Save the file, restart Nginx, and you should be fine.

Good luck, googlers :slight_smile:

1 Like

Thank you for this! I am trying out my Wordpress on Virtualmin using Nginx, your solution fixed the broken permalinks issue.

1 Like

It worked for me too; just needed to clean up the formatting a little. I’m brand new to Nginx, so this was a big help.

fastcgi_hide_header X-Powered-By;

enforce NO www

if ($host ~* ^www.(.)) {
set $host_without_www $1;
rewrite ^/(.
)$ $scheme://$host_without_www/$1 permanent;
}

unless the request is for a valid file, send to bootstrap

if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}