【问题标题】:SEO friendly URL (Permalinks) not working for Wordpress on NGINXSEO 友好的 URL(永久链接)不适用于 NGINX 上的 Wordpress
【发布时间】:2017-11-21 23:05:55
【问题描述】:

我们在 NGINX 服务器的子目录中安装了 wordpress。我们希望我们的博客 URL 类似于 www.example.com/blog。单个博客文章的 url 应该类似于 www.example.com/blog/post-name。为此,当我们进入 wordpress 中的设置-> 永久链接菜单并将其从默认更改为帖子名称时,它开始出现错误。但是,当我们将其保留为默认值时(www.example.com/blog/?p=123),它就可以正常工作。 博客目录安装在 nginx 的 html 文件夹下。 我们在 nginx.conf 文件中添加了以下条目:

location /blog {

root /usr/share/nginx/html;
index index.html index.php;
try_files $uri $uri/ /index.php?$args;

location ~ \.php$ {
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass   127.0.0.1:9000;
}
}

blog 目录与我们的主站点 (example.com) 的文件夹安装在同一级别。 我们做错了什么?

【问题讨论】:

  • 是 404 错误吗?如果是这样,您是否检查过我认为您的 Apache 设置允许 rewrite_module
  • 我们使用的是 nginx,并且内置了 rewrite_module。serverfault.com/questions/305780/…

标签: php wordpress nginx


【解决方案1】:

试试这个,

location /blog/ {
    root /usr/share/nginx/html;
    index index.html index.php;
    try_files $uri $uri/ /blog/index.php?$args;
}

【讨论】:

  • 只有一件事 - 现在 wordpress 无法选择我们的任何 css/js/image 文件。我们是否需要在 location 中为此添加任何特定条目?
【解决方案2】:

有一个类似的问题,我在我的 nginx conf 中添加了这个,以使其适用于 nginx hhvm 3.21 中的 wordpress /index.php/permalink url

添加此供大家参考:

location / {

    ...
    fastcgi_param  SCRIPT_FILENAME $document_root/index.php$fastcgi_script_name;


}

location / {

    rewrite ^/([^\.]+)$ /index.php/$1 break;

}

确保您使用的是 fastcgi 而不是服务器版本(在服务器版本中,您可能会因为重写而获得太多重定向)

  • 已测试
  • 质量检查通过

【讨论】:

    猜你喜欢
    • 2014-07-01
    • 2016-05-18
    • 2014-08-28
    • 2018-04-01
    • 2011-11-18
    • 2013-03-26
    • 1970-01-01
    • 2012-09-11
    • 1970-01-01
    相关资源
    最近更新 更多