[英]WordPress 3.0 & nginx - permalink, 404 problem
我在我的服务器上安装了nginx,FastCGI和PHP。 WordPress 3.0安装了一些怪物之后的战斗,但它的安装和运行良好。
但是,当我将固定链接设置更改为默认设置以外的任何设置时,我会在每个帖子,文章和页面上收到404错误。
我知道这与nginx不支持.htaccess和WordPress与页面被请求时的去向相混淆。
我在nginx conf文件甚至nginx兼容性插件中尝试了一些重写; 都没有奏效。 通过一次重写,我设法停止了404错误,但是在我获得PHP确认页面之后,我没有找到WordPress的帖子。 呸。
论坛上到处都是类似问题的人。 有没有人有办法解决吗?
在你的位置/街区,
添加此项并删除任何非特定的重写规则:
try_files $uri $uri/ /index.php;
如果wordpress在根目录之外的另一个目录上,而不是
if (!-e $request_filename) {
rewrite ^/wordpress/(.+)$ /wordpress/index.php?q=$1 last;
}
你可以有:
location /wordpress {
try_files $uri $uri/ /wordpress/index.php?$args;
}
此页面具有完全相同的概念。 我应该首先阅读并尝试它: 在子目录下的nginx重写规则
痛苦之后:
# 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;
}
如果请求的文件不存在,请将其传递给index.php。 它有点慢,我想我可能会尝试不使用查询,但它确实有用...... :)
这就是我在dreamhost中的wordpress博客中解决我的永久链接的方法。
在文件夹/home/ftpusername/nginx/example.com/
(如果没有,请创建它)
使用以下内容创建了文件nginx.conf
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
重新启动了nginx
/etc/init.d/nginx重新加载
一些说明:
ftpusername和example.com必须根据您的系统进行更改。
就是这样!
祝大家好运。
你试过nginx兼容性插件吗?
加上ElasticDog似乎提供了一篇关于让WP与nginx一起工作的相当简洁的文章 - 其中包括让相当多的永久链接工作。
这是另一篇似乎专门针对WordPress的nginx重写规则的文章 。
如果你使用/ like之外的位置,这不起作用:
〜.php $,我的意思是说漂亮的链接可以工作,但你的图形将遍布整个地方。 所以你需要的是下面的确切说明。
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;
}
我做了以下..
在/home/userrunningnginx/nginx/domain.com文件夹中
我有:
default.conf(文件)
include /home/neukbaarofnietps/nginx/neukbaarofniet.com/drop;
丢弃(文件)
# 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(文件)
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
WORDPRESS-NGINX.CONF(文件)
#######################
# 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;
}
将此块添加到您的nginx.conf应解决此问题:
if (!-e $request_filename) {
rewrite ^/wordpress_dir/(.+)$ /wordpress_dir/index.php?q=$1 last;
}
希望这可以帮助。
祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.