【问题标题】:Nginx setup for Wordpress does not link posts correctlyWordpress 的 Nginx 设置无法正确链接帖子
【发布时间】:2018-04-29 21:55:56
【问题描述】:

我目前有一个 WordPress 站点,该站点当前安装在一个子目录中。不过好像有问题。

网站按预期显示,但帖子要么有 404 错误页面,要么重定向到网站的根目录。这是我目前在服务器上的设置截图:

如果有人可以请在这里帮助我。我会很感激的。

更新(2018 年 4 月 29 日):

我一直在努力,它已经到了博客页面打开的地步,但是,帖子出现了来自 ROOT 站点的 404 错误消息。

例如: 打开子目录 (example.com/blog) 时,会出现该站点。单击帖子时,将显示 404 页面,但在 example.com 站点上。

这让我相信 2 个 WordPress 安装存在问题,但我不能确定。

这是我的根目录和博客的 Nginx 配置:

        location /blog {
            root /var/www/html/aus;
            index index.php index.html;

            access_log /var/log/nginx/blog.access.log;
            error_log /var/log/nginx/blog.error.log;

            try_files $uri $uri/ /blog/index.php$is_args$args;
            if (!-e $request_filename) {
                    rewrite ^.*$ /blog/index.php last;
            }
        }

        location / {
            access_log /var/log/nginx/root.access.log;
            error_log /var/log/nginx/root.error.log;

            #try_files $uri $uri/ =404;
            gzip off;
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_intercept_errors on;
            fastcgi_ignore_client_abort off;
            reset_timedout_connection on;

            include fastcgi.conf;
            fastcgi_param SERVER_PORT 80;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
        }

【问题讨论】:

  • 不应将配置显示为图像,而应显示为代码。
  • @timiTao 对不起。下次我会把它显示为代码。

标签: wordpress nginx url-rewriting configuration-files permalinks


【解决方案1】:

如果您收到 404 错误页面或其他帖子错误,请重置您的永久链接设置。

转到设置→永久链接并将其重置为默认设置并保存。

【讨论】:

  • 感谢您的回复。我试过这个,这似乎出现了同样的错误。我可以想象这是一个重写问题?
  • 尝试通过引用link添加默认htaccess代码,然后检查404错误。
  • 我还添加了默认的 htaccess,但是,这在网站上没有任何作用。
【解决方案2】:

你的 nginx 配置应该是这样的:

上游 php-upstream { 服务器 unix:/var/run/php5-fpm.sock fail_timeout=0; }

    ...

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

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_intercept_errors on;
            fastcgi_ignore_client_abort off;
            reset_timedout_connection on;

            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            include fastcgi.conf;
            fastcgi_param SERVER_PORT 80;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass php-upstream;
            fastcgi_index index.php;
    }

    ...

这是一个 wordpress 网站的工作 nginx 配置的摘录。当然,您应该调整它并相应地修改它以满足您的需求。

【讨论】:

  • 感谢@bogdan 的这个提示。但是我已经尝试过了,它似乎仍然不起作用。这是正确的: location /blog/ { try_files $uri $uri/ /index.php?$args; location ~ \.php$ { } }
  • 嗨@bogdan。感谢您的答复。我已经找到了解决这个问题的方法,现在看起来很好。我现在遇到一些帖子链接到根服务器而不是子目录的问题。这会是重写问题吗?
  • 我认为这不是重写问题的必要条件,而是链接就像数据库中的那样。您可能应该检查您网站数据库中的条目并修改它们以满足您的需要
  • 我已经查看了数据库中的条目,但是它们似乎是正确的。 Wordpress 中有一些帖子会转到正确的子文件夹帖子。但是有些帖子会转到根 URL(这是错误的)。还有其他可能的建议吗?
猜你喜欢
  • 2014-05-13
  • 1970-01-01
  • 1970-01-01
  • 2019-02-06
  • 1970-01-01
  • 1970-01-01
  • 2016-04-12
  • 1970-01-01
  • 2021-04-06
相关资源
最近更新 更多