这几日将几个WordPress的Web服务器从Apache切换到了Nginx,正中间遇到了很多难题,因而纪录1下,便于往后维护保养应用。 针对WordPress站点来讲,固定不动连接关键是根据根文件目录下的.htaccess文档来操纵,切换服务器后,Nginx的rewrite文件格式和Apache的不一样,必须改动。 先卸载Apache系统软件,以后安裝Nginx系统软件。 在BT面板后台管理,点“网站”-“设定”-“伪静态数据”,针对单站点的WordPress来讲,本来的.htaccess文档內容以下: RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L] 切换到Nginx系统软件后,其配备內容以下: location / {try_files $uri $uri/ /index.php?$args;}rewrite /wp-admin$ $scheme://$host$uri/ permanent; 针对子网站域名方法的多站点的WordPress来讲,本来的.htaccess文档內容以下: RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteRule ^wp-admin$ wp-admin/ [R=301,L]RewriteCond %{REQUEST_FILENAME} -f [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^ - [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 OnRewriteCond %{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;} (责任编辑:admin) |