升级NginX从1.18.0到1.23.0在Ubuntu 20.04 LTS - Wordpress页面的url所有功能



当我完成上述操作后,相关wordpress站点的永久链接就停止工作了。

wordpress网站本身和所有。php和。html文件呈现良好,只是任何子页面(主页除外)现在无效,点击任何wordpress页面链接在wordpress网站上生成404错误。

奇怪的是,wordpress "/admin"页面在NginX 1.18.0和NginX 1.23.0下仍然100%正确工作-管理后端也使用看起来像永久链接的东西…

这是我的/etc/nginx/conf.d/default.conf的新实例,我使用了相同的文件在我的1.18.0安装在我的1.23.0 Ubuntu 20.04安装:

server {
listen       80;
root /var/www/wordpress;
server_name www.myserver.com
client_max_body_size 100M;
autoindex off;
location / {
root   /var/www/wordpress;
index  index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args =404;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass   unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny  all;
}
location ~ /. {
deny  all;
}
}

在Nginx下修复Wordpress永久链接的几个建议已经被纳入,例如这些是谷歌的建议:

try_files $uri $uri/ /index.php?$args =404;

iso

try_files $uri $uri/ =404;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

位置~ .php$块。

没有效果。我在网站上访问的任何子页面URL都给出了404。

子页面url是典型的wordpress url,例如

www.myserver.com/home/top-content
www.myserver.com/home/get-in-thouch

等。当这个wordpress站点部署在Ubuntu 20.04的NginX 1.23.0下时,这些都被破坏了,如果点击会导致404。

以上内容可以在NginX 1.18.0和Wordpress 6.0.1中正常工作,NginX 1.23.0不能/不提供Wordpress永久链接功能,上面的/etc/NginX/conf.d/default.confconfig .

我错过了什么让WordPress永久链接功能回到NginX 1.23.0 -显然在NginX 1.23.0和NginX 1.18.0中如何配置有一些差异?

谢谢!

好的,这个问题通过添加

解决了
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}

到my/etc/nginx/conf.d/default.conf然后重新启动NginX和php8.1-fpm。

E。/etc/nginx.conf.d/default.confNginX 1.23.0下的文件。需要上述添加以提供相同的wordpress永久链接功能,因为我在NginX 1.18.0下使用相同的PHP和wordpress实例。

/etc/nginx.conf.d default.conf在NginX 1.23.0中,wordpress的permalink兼容状态是

server {
listen       80;
root /var/www/wordpress;
server_name www.msbmanagement.co.za;
client_max_body_size 100M;
autoindex off;
location / {
root   /var/www/wordpress;
index  index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args =404;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}
#THIS WAS REQUIRED TO BE ADDED FOR NGINX 1.23.0 BEGIN
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}
#THIS WAS REQUIRED TO BE ADDED FOR NGINX 1.23.0 END
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass   unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny  all;
}
location ~ /. {
deny  all;
}
}

希望这能帮助到别人。显然,在NginX 1.18.0和NginX 1.23.0中,wordpress永久链接URL重写存在一些差异。

最新更新