【问题标题】:Permalinks not working on nginx centos 7永久链接在 nginx centos 7 上不起作用
【发布时间】:2016-12-28 02:24:03
【问题描述】:

我已经在 centos 7 上安装了一个 vps,带有 nginx、php-fpm、phpmyadmin、mariadb。我已经设置了一个域,然后在 /enter/gallery 等两个不同的文件夹中安装了 2 个 WordPress。

当我将永久链接从默认更改为其他任何内容时,帖子和页面不起作用。它显示404错误。我停用了所有插件,然后将永久链接设置为帖子名称,然后编辑配置文件,保存并重新启动 nginx。还是不行。

这是我的 nginx 服务器块。我需要更改它以使网站 SEO 友好。

server {
    listen       80;
    server_name  domain.com [url]www.domain.com;[/url]
    root   /var/www/domain.com/html;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    error_page 404 /index.php;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www/domain.com/html;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
       fastcgi_index index.php;
    }
}

【问题讨论】:

  • 您的 root 设置为 /var/www/domain.com/html,但您提到您有两个不同的 wordpress 安装正在运行。您需要确保为每个目录设置了正确的文档根目录以及它们需要的任何重写规则。这个问题太宽泛,无法提供任何有用的答案。请尝试进一步缩小范围并重新发布更详细的问题。

标签: php wordpress nginx centos7


【解决方案1】:

漂亮的永久链接需要由相应 WordPress 安装的 index.php 脚本处理。您目前正在将所有内容重定向到 URI /index.php,从您的问题来看,/var/www/domain.com/html/index.php 似乎不存在。

如果您有两个单独的 WordPress 安装,在 /enter/gallery 下,您需要为每个安装位置定义一个默认脚本:

location /enter {
    try_files $uri $uri/ /enter/index.php;
}
location /gallery {
    try_files $uri $uri/ /gallery/index.php;
}

【讨论】:

  • 非常感谢理查德·史密斯。您节省了我的时间。它适用于永久链接以及 404 错误页面重定向到索引页面。谢谢
猜你喜欢
  • 1970-01-01
  • 2015-04-28
  • 2016-12-07
  • 2015-03-05
  • 2011-05-18
  • 2015-07-03
  • 1970-01-01
相关资源
最近更新 更多