WordPress Permalink Problem with Nginx webserver

4 posts / 0 new
Last post
#1 Mon, 05/21/2012 - 01:45
anand_n

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

Sun, 10/20/2013 - 22:49
lizbog3

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 :)

Sun, 02/14/2016 - 17:23 (Reply to #2)
jaldeguer

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

Mon, 03/06/2017 - 14:38
laith

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;
}
Topic locked