永久链接不适用于 nginx centos 7
Permalinks not working on nginx centos 7
我在 centos 7 上安装了 vps 和 nginx,php-fpm,phpmyadmin,mariadb。我设置了一个域,然后在两个不同的文件夹中安装了 2 个 WordPress,例如 /enter
和 /gallery
.
当我将永久链接从默认设置更改为其他任何内容时,post 和页面无法正常工作。它显示 404 错误。我停用了所有插件,然后将永久链接设置为 post 名称,然后编辑配置文件,保存并重新启动 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;
}
我在 centos 7 上安装了 vps 和 nginx,php-fpm,phpmyadmin,mariadb。我设置了一个域,然后在两个不同的文件夹中安装了 2 个 WordPress,例如 /enter
和 /gallery
.
当我将永久链接从默认设置更改为其他任何内容时,post 和页面无法正常工作。它显示 404 错误。我停用了所有插件,然后将永久链接设置为 post 名称,然后编辑配置文件,保存并重新启动 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;
}