PHP(FastCGI)がNginxのaliasの下で404エラーの解決方法が現れる

914 ワード

本論文では,Nginxのalias下でPHP(FastCGI)が404エラーを生じる解決法について述べた.皆さんの参考にしてください.具体的には以下の通りです.
Nginxの公式wikiでは以下のように説明されています
The alias directive cannot be used inside a regex-specified location. If you need to do this you must use a combination of rewrite and root.
実際の使用ではaliasの下のphpは404を返し、htmlは確かに正常に表示され、解決方法は以下の通りである.

location / {
root /opt/www/htdocs/www;
index index.php index.html index.htm;
}
location /bbs/ {
alias /opt/www/htdocs/bbs/;
index index.php index.html index.htm;
}
location ~ ^/bbs/.+.php{
root /opt/www/htdocs;
rewrite /bbs/(.*.php?) /1 break;
include conf/fcgi.conf;
fastcgi_pass 127.0.0.1:10080;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/www/htdocs/bbs$fastcgi_script_name;
}


すなわちaliasをrootとrewriteで置き換える
本稿では,nginxプラットフォーム上のphpプログラム設計に役立つことを期待する.