【问题标题】:WordPress 3.0 & nginx - permalink, 404 problemWordPress 3.0 & nginx - 永久链接,404 问题
【发布时间】:2010-07-15 12:22:48
【问题描述】:

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

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

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

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

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

【问题讨论】:

标签: wordpress nginx permalinks


【解决方案1】:

在您的位置/街区,

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

try_files $uri $uri/ /index.php;

【讨论】:

  • 这没有问题,根据 nginx 官方 wiki,这是推荐的解决方案。
  • 这里是关键:它必须是您的 / 目录。如果你把它放在你的 /blog 目录或其他任何地方,你仍然会得到 404 错误。
  • wiredniko - 将您的目录位置放在 index.php 之前。在您的情况下 /index.php 将转向 /blog/index.php 。
【解决方案2】:

如果 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

【讨论】:

    【解决方案3】:

    痛苦之后:

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

    【讨论】:

    • 很高兴听到您取得了突破!抱歉@Taffy,我没有使用 nginx 的经验,但我会尽我所能提供帮助;)
    • 你不需要使用重写搜索; see the answer here
    【解决方案4】:

    你试过nginx Compatibility plugin吗?

    加上 ElasticDog 似乎提供了一个相当的concise article on getting WP working with nginx - 其中包括获得漂亮的永久链接。

    这是另一篇似乎专门针对 nginx rewrite rules for WordPress 的文章。

    【讨论】:

    • 是的,插件累了 - 不起作用。我也遵循了 ElasticDog 的教程,我现在正在使用他的大部分配置。我也关注了wiki.dreamhost.com/Nginx 并了解其中的大部分内容(我认为!),但同样的问题。每当我将永久链接更改为默认值以外的任何内容并尝试访问帖子、文章或页面时,我都会收到“未指定输入文件”。错误。我假设 WordPress(和重写)没有告诉 WordPress 该做什么,但我无处可去...... :(
    • 插件确实有效,只是你需要做另一件事:piran.com.au/2011/10/nginx-and-wordpress-permalinks
    • @Rich 您的链接现在是 404,这就是为什么最好将重要信息摘录到答案的编辑或您自己的答案中。
    【解决方案5】:

    这就是我在 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 必须根据您的系统进行更改。

    就是这样!
    祝大家好运。

    【讨论】:

      【解决方案6】:

      如果您使用的是 /like 以外的位置,则此方法不起作用:

      ~ .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;
        }
      

      【讨论】:

        【解决方案7】:

        我做了以下..

        在文件夹中 /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;
        }
        

        【讨论】:

          【解决方案8】:

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

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

          希望这会有所帮助。

          祝你好运。

          【讨论】:

            猜你喜欢
            • 2015-02-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-07-19
            • 1970-01-01
            相关资源
            最近更新 更多