WordPress generally works out-of-the box on nginx.
The posts load fine all the functions in the dashboard works pretty well. That is, until you come to the permalinks.
If you are using WordPress on Apache (with mod_rewrite), WordPress will automatically add the required rewrite rules to your .htaccess
file for permalinks to work. But for nginx, you have to add the rules manually.
Moreover, when WordPress detects that mod_rewrite is infact not loaded (which is the case with nginx), it falls back to using PATHINFO permalinks, which inserts an extra ‘index.php’ in front.
This isn’t much of a problem forif you are using the custom structure option to remove the index.php.
To make the permalinks work, you will need to edit your nginx configuration file, here we will use the try_files directive (available from nginx 0.7.27+) to pass URLs to WordPress’s index.php for them to be internally handled. This will also work for 404 requests.
If your blog is at the root of the domain (something like http://www.yourdomainname.com), find the
1 |
location/ |
block inside the configuration file, and add the following line to it.
1 |
try_files $uri $uri/ /index.php?$args; |
Here, Nginx checks for the existence of a file at the URL ($uri
), then for a directory ($uri/
).
If it doesn’t find a directory or a file, it performs an internal redirect to /index.php
passing the query string arguments as parameters.
It should look like this after the edits :
1 2 3 4 5 |
location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; } |
If your blog is in a subfolder (say /wordpress), you’ll have to add an extra location /wordpress/
block to your configuration file :
1 2 3 4 |
location /wordpress/ { try_files $uri $uri/ /wordpress/index.php?$args; } |
After you have finished making the changes in the configuration file, reload the nginx configuration by :
1 2 |
/etc/init.d/nginx reload |
Wordpress’ pretty permalinks should work fine now.
This worked for me! great post, thank you.
Thanks, very useful!
Very clear instructions, it worked for me!!
Thanks a lot!!
I must express my apiticearpon to this writer for bailing me out of this situation. As a result of browsing throughout the online world and meeting tips that were not helpful, I believed my life was well over. Living without the approaches to the issues you have resolved through the review is a critical case, as well as the ones which may have in a wrong way affected my entire career if I hadn’t encountered your web blog. The training and kindness in touching a lot of stuff was tremendous. I am not sure what I would’ve done if I hadn’t come upon such a subject like this. I am able to at this point relish my future. Thanks a lot so much for your reliable and amazing help. I will not be reluctant to recommend your web sites to anyone who ought to have tips about this matter.
Thanks a lot! Your article saved me a lot of time on researching, I was pulling my hair out! I’m pretty new to Nginx and I’ve just had it set up on my first self managed VPS ever, it’s a dream came true!
Although I know that Nginx configuration for WordPress depends a lot on each project’s demands, I’d really appreciate if I could find somewhere a basic but improved Nginx configuration template for a WordPress install with proper caching set up related to plugins such as WP Super Cache and W3 Total Cache.
I’ve seem a lot of sample configurations out there but most of them are too focused on “sysadmin” heavy tech programming language, so I still don’t feel comfortable yet messing up with my fresh Nginx install.
Regarding the WP permalinks issue, I remember that while I was researching, I’ve come through a similar post that probably had the very same solution for it, but as I’ve mentioned, it was one of those tech programming articles which sounds so unnatural to me and for this reason I must have missed it.
Your article was very well written and easy to be understood for a GUI guy like me, again, thanks for sharing!
thanks. it worked for me
How about subdomain? (wp.example.com)
Tried you way, but still 404…
Depends on your nginx config.
Could you post it on http://noted.pw and post the link as a comment here?
You also have to enable pretty permalinks in wordpress.
my sub folder WordPress not working.
URL of sub folder wp https://findatips.com/bn/
https://findatips.com/bn/make-money/30/ its return 404 error from main site https://findatips.com
location /bn/ {
try_files $uri $uri/ /bn/index.php?$args;
}
added to /conf.d/common at the bottom
Sometimes I’ve noticed that you need to save the Permalinks settings twice in WordPress to make it work after changing the rules for nginX.
have you reloaded the nginX config without errors?
This post was copied without even attribution from http://nginxlibrary.com/wordpress-permalinks/
Anyway.. I have already reported there, search for my last name, one case in which it is not working. If anybody looking after this page can read there and give advice, it would be great.. thanks
Hello,
Thanks Buddy,
This worked for me! great post, thank you.
I am afraid that all I get after applying the above solution (for a sub-folder install) is an index of the site
So jealous of all those who have it working
Running on localhost using wpn-xm
Hi, nice and very interesting topic,, but it does NOT working for me either.
I wish also to find a way to make the permalinks to work on my WP sites with nginx.
Something links ok, but many links not good.
I try to set WP woocommerce script theme called ALOSHOP, I bought on envato market.
http://thebeijingqueen.com/demoalo1/
Links; My Account; Wish List; Compare; Login; Register; and many more t all redirect to the script vendor url address.
I also think the script got a problem itself, but the seller says no, they say it is my Nginx server setup.
I run the script in subfolders so I add the above changes to mydomain.com vhost but still not working.
I am lost and very sad with it,,,
hi can you please suggest the path of the nginx configeration file and its exact name please?