PHP of FastCGI resolution of a 404 error under alias of Nginx
- 2020-05-10 23:32:18
- OfStack
This article describes the solution to the 404 error in PHP(FastCGI) under alias of Nginx. I will share it with you for your reference as follows:
In Nginx's official wiki, it is described below
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.
In practice, php under alias returns 404, while html does display normally. 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 has been helpful to the php programming on the nginx platform.