/alidata/server/nginx/ ├── conf/ │ ├── rewrite/ # 偽靜態規則檔目錄 │ │ ├── phpwind.conf │ │ ├── discuz.conf │ │ └── wordpress.conf │ └── vhosts/ # 網站虛擬主機設定 │ └── yoursite.conf
cd /alidata/server/nginx/conf/rewrite ls # 若無所需程式規則,建立 新程式.conf vi 新程式.conf # 貼上對應 Rewrite 規則
vi /alidata/server/nginx/conf/vhosts/yoursite.conf
在 server { } 區塊內加入:
include rewrite/新程式.conf;
/alidata/server/nginx/sbin/nginx -t # 輸出 syntax is ok / test is successful 表示通過 /alidata/server/nginx/sbin/nginx -s reload
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last; rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$3&page=$4 last; rewrite ^(.*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last; rewrite ^(.*)/space-(username|uid)-([0-9]+)\.html$ $1/home.php?mod=space&$2=$3 last; rewrite ^(.*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last; rewrite ^(.*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
nginx -T 輸出完整合併後配置,檢查 include 是否生效/alidata/server/nginx/logs/error.log 查看 rewrite 錯誤