欢迎来到站长天空!

WordPress

当前位置: 主页 > CMS教程 > WordPress

WordPress切换到Nginx服务器

时间:2025-11-11 15:19:29|栏目:WordPress|点击:

这几天将几个WordPress的Web服务器从Apache切换到了Nginx,中间遇到了不少问题,因此记录一下,以便日后维护使用。

对于WordPress站点来说,固定链接主要是通过根目录下的.htaccess文件来控制,切换服务器后,Nginx的rewrite格式和Apache的不同,需要修改。

先卸载Apache系统,之后安装Nginx系统。

WordPress

在BT面板后台,点“网站”-“设置”-“伪静态”,对于单站点的WordPress来说,原先的.htaccess文件内容如下:

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

切换到Nginx系统后,其配置内容如下:

location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

对于子域名方式的多站点的WordPress来说,原先的.htaccess文件内容如下:

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*.php)$ $1 [L]
RewriteRule . index.php [L]

切换到Nginx系统后,其配置内容如下:

if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*.php)$ $1 last;
rewrite ^ /index.php last;
}

此外,服务器上还安装了v2ray,原先在Apache里配置的内容如下:

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /test/(.*)           ws://127.0.0.1:11111/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /test/(.*)           http://127.0.0.1:11111/$1 [P,L]

切换到Nginx后,在Nginx服务器配置文件里修改的内容如下:

location /test/ {
proxy_pass http://127.0.0.1:11111/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}


上一篇:WordPress生成HTML静态化网站

栏    目:WordPress

下一篇:wordpress建立数据库连接时出错怎么办?

本文标题:WordPress切换到Nginx服务器

本文地址:https://zz.feitang.co/CMSjiaocheng/25976.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2025 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号