This article describes a workaround for PHP (FastCGI) with a 404 error in the Nginx alias. Share to everyone for your reference, specific as follows:
As described in the official wiki of Nginx
The alias directive cannot be used inside a regex-specified location. If you are need to does this with must use a combination of rewrite and root.
In the actual use of the alias below the PHP return 404, and HTML can be correctly displayed, the solution is as follows
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;
}
Replace alias with Root plus rewrite
I hope this article will help you with the PHP program design on the Nginx platform.