永久链接在nginx centos 7上不起作用


Permalinks not working on nginx centos 7

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

当我将永久链接从默认更改为其他内容时,帖子和页面不起作用。显示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;
    }
}

漂亮的永久链接需要由适当的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;
}