Solution to the problem that nginx cannot find the php process: 1. Modify the configuration of nginx.conf; 2. Use try_files to capture non-existent urls and return an error.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if nginx cannot find the php process? ?
nginx cannot find php file
Use php-fpm to parse PHP. "No input file specified" and "File not found" are common errors that cause headaches for new nginx users. The reason The php-fpm process cannot find the .php file configured by SCRIPT_FILENAME to be executed, and php-fpm returns the default 404 error prompt to nginx.
For example, my website does not have test.php under document_root. When accessing this file, you can see the returned content by capturing the packet.
HTTP/1.1 404 Not Found Date: Fri, 21 Dec 2012 08:15:28 GMT Content-Type: text/html Proxy-Connection: close Server: nginx/1.2.5 X-Powered-By: PHP/5.4.7 Via: 1.1 c3300 (NetCache NetApp/6.0.7) Content-Length: 16 File not found.
Many people don’t want users to see this default 404 error message directly, and want to customize the 404 error.
Before giving a solution Let's first analyze how to avoid this type of 404 error, and then talk about what to do when this happens (for example, the user enters a path that does not exist by mistake) so that a custom 404 error page can be displayed.
1. The wrong path is sent to the php-fpm process
When this kind of error occurs, nine out of ten it is the back-end fastcgi process that receives the wrong path (SCRIPT_FILENAME), and the back-end fastcgi Most of the reasons for receiving error paths are configuration errors.
The common nginx.conf configuration is 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_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/example.com$fastcgi_script_name; include fastcgi_params; } }
There are many unreasonable things in this configuration. One of the obvious problems is that the root directive is placed in location / piece. If the root directive is defined in a location block, the root directive can only take effect in the location where it is located. There is no root directive in other locaionts. For example, the location /images block will not match any request. You need to configure the root directive repeatedly in each request to solve this problem. Therefore, we need to put the root directive in the server block, so that each location will inherit the documentroot defined by the parent server block. If a location needs to define a different document_root, you can define a separate root directive in the location.
Another problem is that the fastCGI parameter SCRIPT_FILENAME is hard-coded. If you modify the value of the root directive or move the file to another directory, php-fpm will return the "No input file specified" error, because SCRIPT_FILENAME is hard-coded in the configuration and does not change with the change of $document_root. We can modify it. SCRIPT_FILENAME is configured as follows:
fastcgi_param SCRIPT_FILENAME documentrootfastcgi_script_name;
So we cannot forget to configure the root directive in the server block, otherwise the value of documentroot will be empty and only fastcgi_script_name will be passed to php-fpm, which will result in " No input file specified" error.
2. The requested file really does not exist
When nginx receives a request for a .php file that does not exist, because nginx will only check whether $uri is If the file ends with .php, it will not judge whether the file exists. Requests that end with .php will be sent directly to php-fpm by nginx for processing. If the file cannot be found during php-fpm processing, it will return "No input file specified" with a "404 Not Found" header.
Solution
We intercept non-existent files in nginx, request and return a custom 404 error
Use try_files to capture non-existent urls and return errors.
location ~ .php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME .... ................................... ................................... }
The above configuration will check whether the .php file exists. If it does not exist, a 404 page will be returned.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if nginx cannot find the php process?. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool