Nginx File not found error

Source: Internet
Author: User

Using PHP-FPM to parse PHP, "No input file specified", "File not found" is a common bug that makes nginx novice headache, because PHP-FPM process can not find Script_ FileName configuration of the. php file to execute, php-FPM returns the default 404 error prompt to Nginx. For example, my website doucument_root no test.PHP, when you access this file, you can see what is returned by grabbing the packet. HTTP/1.1 404Not FoundDate: Fri, 2012 08:15:28gmtcontent-type:text/Htmlproxy-connection:CloseServer: nginx/1.2.5X-powered-by:php/5.4.7Via: 1.1 c3300 (Netcache netapp/6.0.7) Content-length:16FileNot found.Many people don't want users to see this default 404 error message directly and want to customize the 404 error.before we give a solution, let's analyze how to avoid such a 404 error, and then say what to do if the user enters a path where the error does not exist, in order to display the custom 404 error page
One, the wrong path is sent to php-The FPM process has this type of error, 10 of nine are the backend fastcgi process received the error path (script_filename), the back end fastcgi received the wrong path is mostly a configuration error. Common Nginx.the Conf is configured as follows: server {Listen [::]:80; server_name Example. com www.example.com; Access_log/var/www/logs/example.com.access.Log; Location/{root/var/www/example.com; Index index. HTML index.htm Index.PL; } Location/images {AutoIndex on; } Location~ \.php$ {fastcgi_pass127.0.0.1:9000; Fastcgi_index Index.PHP; Fastcgi_param Script_filename/var/www/example.com$fastcgi _script_name; includeFastcgi_params; }} There are a lot of unreasonable aspects in this configuration, one obvious problem is that the root command is placed in the locationBlock If the root command is defined in the location block, then the root command can only be applied to where it resides. There are no root commands in other locaiont, such as the location/images block does not match any requests and needs to be repeated in each request to configure the root command to resolve this issue. So we need to put the root command in the server block so that each location inherits the parent server block definition$document _root, if a location needs to define a different$document _root, you can define a single root command at location. Another problem is that the fastcgi parameter script_filename is written dead. If you change the value of the root command or move the file to another directory, PHP-FPM will return "No inputfileSpecified "error because script_filename is written dead in the configuration and does not followChange $doucument _root, we can modify the Script_filename configuration as follows: Fastcgi_param script_filename$document _root$fastcgi_script_name; So we can't forget to configure the root command in the server block, otherwisethe value of the $document _root is empty, it will only pass$fastcgi _script_name to PHP-FPM, this will result in "No inputfilespecified "error. Second, the requested file really does not exist when Nginx received a not in theThe. php file is requested, because Nginx will only check$uri Whether it isAt the end of PHP, there is no judgment on whether the file exists or not. PHP end-of-request Nginx will be sent directly to PHP-FPM processing. PHP-FPM processing when the file is not found will return "no inputfileSpecified "with" 404Not Found "head. Workaround we intercept nonexistent files in Nginx, request and return custom 404 error using Try_files to catch a nonexistent URLs and return an error. Location~ .php$ {try_files$uri=404; Fastcgi_pass127.0.0.1:9000; Fastcgi_index Index.php; Fastcgi_param script_filename.... ................................... ...................................the configuration above will checkThe. php file exists and returns a 404 page if it does not exist.

Nginx File not found error

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.