PHP (FastCGI) 404 error resolution in Nginx alias _nginx

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.