LNMP(Linux + Nginx + MySQL + PHP)架構下,WordPress 後台啟用「固定鏈接」後,內頁出現 404。原因在於 Nginx 不支援 Apache 的 .htaccess,需在虛擬主機配置中直接引入重寫規則。
路徑:/usr/local/nginx/conf/wordpress.conf
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;
}
若內容不同,請覆蓋為上述規則。
編輯站點配置檔(通常位於 /usr/local/nginx/conf/vhost/您的域名.conf):
server {
listen 80;
server_name www.yourdomain.com;
index index.html index.php;
include wordpress.conf; # 新增此行
# ... 其他配置
}
/root/lnmp restart
# 或
/usr/local/nginx/sbin/nginx -s reload
LNMP 一鍵包預設 conf/ 目錄通常已內建 discuz.conf、typecho.conf、drupal.conf 等,同樣透過 include xxx.conf; 引入即可。
root 指令指向的網站根目錄是否正確。