开发者

WordPress 3.0 & nginx - permalink, 404 problem

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开发者_JAVA技巧 merely got my PHP confirmation page. Bah.

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


On your location / block,

add this and remove any non-specific rewrite rules:

try_files $uri $uri/ /index.php;


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


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


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.


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.


this does not work if you are using location other than / like:

~ .php$, what i meant to say that pretty link will work but your graphics will be all over the place. so what you need is exactly stated below.

http://www.pearlin.info

  location ~ \.php$



   {
        try_files $uri $uri/ /index.php?$uri&$args;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

  if (!-e $request_filename){
    rewrite ^(.*)$ /index.php?url=$1 break;
  }


I did the following..

in the folder /home/userrunningnginx/nginx/domain.com

I have:

default.conf (file)

include /home/neukbaarofnietps/nginx/neukbaarofniet.com/drop;

drop (file)

# Rather than just denying .ht* in the config, why not deny
# access to all .invisible files
location ~ /\. { deny  all; access_log off; log_not_found off; }

nginx.conf (file)

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

}

WORDPRESS-NGINX.CONF (file)

 #######################
# WP Super Cache

# if the requested file exists, return it immediately
if (-f $request_filename) {
  break;
}

set $supercache_file '';
set $supercache_uri $request_uri;

if ($request_method = POST) {
  set $supercache_uri '';
}

# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}

if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}

# if we haven't bypassed the cache, specify our supercache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host$1/index.html;
}

# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}

# all other requests go to Wordpress
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}


Adding this block to your nginx.conf should solve the issue:

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

Hope this helps.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜