WordPress 3.0 & nginx - permalink, 404 problem

16,770

Solution 1

On your location / block,

add this and remove any non-specific rewrite rules:

try_files $uri $uri/ /index.php;

Solution 2

If wordpress is on another directory besides the root, instead of having

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

You can have:

location /wordpress {
    try_files $uri $uri/ /wordpress/index.php?$args;
}

This page has exactly the same concept. I should have read and tried it first: nginx rewrite rule under a subdirectory

Solution 3

After much pain:

# if filename doesn't exist, take the request and pass to wordpress as a paramater
         if (!-e $request_filename) {
                rewrite ^/wordpress/(.+)$ /wordpress/index.php?q=$1 last;
         }

If the requested file does not exist, pass it to index.php. It's a bit slow and I think I might try and not use a query, but it does work... :)

Solution 4

Have you tried the nginx Compatibility plugin?

Plus ElasticDog seems to provide a fairly concise article on getting WP working with nginx - which includes getting pretty permalinks to work.

Here's another article that seems to deal specifically with nginx rewrite rules for WordPress.

Solution 5

This was how I solved my permalinks in my wordpress blogs in dreamhost.

Inside the folder /home/ftpusername/nginx/example.com/ (if you don't have it, create it)
created the file nginx.conf with the following content

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

restarted the nginx
/etc/init.d/nginx reload

Some notes:
ftpusername and example.com MUST be changed according to your system.

That was it!
Good luck for u all.

Share:
16,770
Admin
Author by

Admin

Updated on July 22, 2022

Comments

  • Admin
    Admin almost 2 years

    I've installed nginx, FastCGI and PHP on my server. WordPress 3.0 installed after a bit of a monster battle, but it's installed and working well.

    However, when I change the permalink settings to anything other than default, I get 404 errors on every post, article and page.

    I understand that this is something to do with nginx not supporting .htaccess and WordPress getting confused with where to go when a page is requsted.

    I've tried a few rewrites in the nginx conf files and even the nginx compatibility plugin; neither have worked. With one rewrite I managed to stop the 404 errors, but instead of WordPress finding the post I was after I merely got my PHP confirmation page. Bah.

    Forums are littered with people with similar issues. Does anyone have a solution?

  • Admin
    Admin almost 14 years
    Yes, tired the plugin - doesn't work. I also have followed ElasticDog's tutorial, I'm using much of his config now. I've also followed wiki.dreamhost.com/Nginx and understand most of it (I think!) but again, same problem. Whenever I change the permalinks to anything other than default and try to access a post, article or page I get the "No input file specified." error. I assume that WordPress (and the rewrites) are failing to tell WordPress what to do, but I'm getting nowhere... :(
  • TheDeadMedic
    TheDeadMedic almost 14 years
    Glad to hear you made a breakthrough! Sorry @Taffy, I've no experience with nginx, but I'll always do my best to help ;)
  • Pablo Olmos de Aguilera C.
    Pablo Olmos de Aguilera C. over 12 years
    This worked without problems, and it's the recommended solution according to the nginx official wiki.
  • Rich
    Rich about 12 years
    The plugin does work, it's just that there's another thing you need to do: piran.com.au/2011/10/nginx-and-wordpress-permalinks
  • New Alexandria
    New Alexandria about 11 years
    @Rich your link is now a 404, which is why it's good to excerpt important info into an edit on the answer, or your own answer.
  • New Alexandria
    New Alexandria about 11 years
    You don't need to use a rewrite search; see the answer here
  • wiredniko
    wiredniko over 10 years
    Here is the key: It has to be your / directory. If you put it in your /blog directory or anywhere else you will get 404 errors still.
  • user2298995
    user2298995 over 9 years
    wiredniko - Put before the index.php your directory location. In your case /index.php would turn to /blog/index.php .