9

我已经在我的服务器上安装了 nginx、FastCGI 和 PHP。WordPress 3.0 经过一番激烈的战斗后安装,但它已安装并且运行良好。

但是,当我将永久链接设置更改为默认值以外的任何设置时,我在每个帖子、文章和页面上都会收到 404 错误。

我知道这与 nginx 不支持 .htaccess 和 WordPress 在请求页面时对去哪里感到困惑有关。

我在 nginx conf 文件甚至 nginx 兼容性插件中尝试了一些重写;都没有工作。通过一次重写,我设法阻止了 404 错误,但在我仅仅得到我的 PHP 确认页面之后,我没有找到 WordPress 的帖子。呸。

论坛上到处都是有类似问题的人。有没有人有办法解决吗?

4

8 回答 8

17

在您的位置/街区,

添加这个并删除任何非特定的重写规则:

try_files $uri $uri/ /index.php;
于 2011-05-18T15:34:29.900 回答
6

如果 wordpress 在根目录之外的另一个目录上,而不是

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

你可以有:

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

此页面具有完全相同的概念。我应该先阅读并尝试过:nginx rewrite rule under a subdirectory

于 2014-06-18T17:03:58.873 回答
5

痛苦过后:

# 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。这有点慢,我想我可能会尝试不使用查询,但它确实有效...... :)

于 2010-07-15T16:40:22.910 回答
2

您是否尝试过nginx 兼容性插件

另外,ElasticDog 似乎提供了一篇关于让 WP 与 nginx 一起工作的相当简洁的文章——其中包括让漂亮的永久链接工作。

这是另一篇似乎专门处理WordPress 的 nginx 重写规则的文章。

于 2010-07-15T13:25:13.877 回答
2

这就是我在 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 reload

一些注意事项:
ftpusername 和 example.com 必须根据您的系统进行更改。

就是这样!
祝你们好运。

于 2013-01-25T23:13:40.810 回答
0

如果您使用的位置不是 / 之类的,这将不起作用:

~ .php$,我的意思是漂亮的链接会起作用,但你的图形会到处都是。因此,您需要的内容如下所述。

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;
  }
于 2013-05-28T18:31:02.810 回答
0

将此块添加到您的 nginx.conf 应该可以解决问题:

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

希望这可以帮助。

祝你好运。

于 2014-07-03T07:52:05.830 回答
0

我做了以下..

在文件夹 /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;
}
于 2013-05-28T22:39:20.330 回答