这几天将几个WordPress的Web效劳器从Apache切换到了Nginx,中央遇到了不少问题,因此记录一下,以便往后保护运用。
闭于于WordPress站点来说,固定链接主假如经过根目录下的.htaccess文件来控制,切换效劳器后,Nginx的rewrite方法和Apache的不共,须要建改。
先卸载Apache体系,之后安置Nginx体系。
WordPress
在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;}