子目錄下 WP 建站 Nginx 反向代理設置 參考官方文件,兩種方式以下都可以實現要求
方法 1,rewrite 方式,適用 php-fpm location /替換子目錄名稱/ { index index.html index.php; if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /替換子目錄名稱/index.php; } }
方法 2,使用 try_files 方式 location /替換子目錄名稱/ { index index.php; try_files $uri $uri/ /替換子目錄名稱/index.php?$args; }
必須要做的,把 wp-admin 單獨處理 rewrite /替換子目錄名稱/wp-admin$ $scheme://$host$uri/ permanent;