尝试了很多教程,但无法在我的本地开发服务器(CentOS 8)上使用它。我可以使用普通/丑陋的永久链接设置来查看和编辑。当我更改为任何其他永久链接设置时,我无法查看或编辑。给出 404。但是,如果我将页面设置为草稿,那么我就可以查看和编辑它们。
这是我的网站结构:
根文件夹是/var/www我的网站位于子文件夹中/var/www/策展
我有两个单独的 Nginx conf 文件/etc/nginx/conf.d/如下:
1. 我的站点安装了 WordPress,但存在永久链接问题:
server {
listen 80;
server_name repository;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /var/www/curation;
index index.php index.html index.htm;
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
#if (!-e $request_filename) {
# rewrite ^/(.*)$ /index.php?q=$1 last;
#}
location /curation/ {
# Setting pretty permalinks in WordPress
# First attempt to serve request as file ($uri)
# or directory ($uri/). If not, redirect to
# /index.php + query string
try_files $uri $uri/ /curation/index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
2. 配置我的根文件夹(除了用于测试的 php 信息文件和索引文件外,该文件夹实际上是空的)。如果有帮助的话,为了便于理解,我将其分享如下:
server {
listen 80;
server_name localhost 192.168.11.8;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /var/www;
index index.php index.html index.htm;
location / {
# First attempt to serve reuqest as file ($uri)
# or directory ($uri/). If not, redirect to
# /index.php + query string
try_files $uri $uri/ /index.php?$args;
# index index.php index.html index.htm;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
我尝试过其他主题的建议,但都没有用。这些是我尝试过的方法。
- 禁用插件以排除诸如 WP Rocket 等缓存插件之类的冲突。
- 所有文件和文件夹均拥有正确的用户所有权nginx:nginx
- 根据 WordPress 建议,将文件和文件夹权限设置为 644 和 755
- 使用以下方法在 wp-config.php 和 wp-content 文件夹上设置 SELinux 可写上下文
sudo chcon -t httpd_sys_rw_content_t /var/www/curation/wp-content -R
整个 WordPress 文件夹是否需要设置 SELinux 上下文可写,我认为这是不可取的。
我很困惑。我做错了什么?我已经做了两天了。任何帮助我都会很感激。
答案1
作为替代解决方案,我已移动将整个站点移至根目录/var/www
,并对 Nginx 站点配置进行了微小编辑
location /curation/ {
try_files $uri $uri/ /curation/index.php?$args;
}
到
location / {
try_files $uri $uri/ /index.php?$args;
}
所有永久链接问题都已解决,我的网站运行良好。
这实际上不是我最初问题的答案子目录中的站点永久链接不起作用. 我不知道为什么它对子目录不起作用。
答案2
看起来该网站已从 移至/curation/
,/
但是location
块并未改变。
区块:
location /curation/ {
try_files $uri $uri/ /curation/index.php?$args;
}
应改为:
location / {
try_files $uri $uri/ /index.php?$args;
}