How to correctly configure Nginx+PHP under Linux
Suppose we use PHP to implement a front-end controller, or to put it bluntly, it is a unified entrance: send all PHP requests to the same file, and then implement routing by parsing “REQUEST_URI” in this file. Generally configured like this At this time, many tutorials will teach you to configure Nginx+PHP like this: server { listen 80; server_name foo.com; root /path; location / { index index.html index.htm index.php; if (!-e $request_filename) { rewrite ./index.php last; } } Location ~ /.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME /path$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; }} There are a lot of mistakes here, or at least bad tastes. You can find a few if you take a look. We need to first understand the inheritance relationship of the instructions in the Nginx configuration file: The Nginx configuration file is divided into many blocks. The common ones from outside to inside are “http”, “server”, “location”, etc. The default inheritance relationship is from outside to inside, which means that the inner blocks will be automatically obtained. The value of…
How to correctly configure Nginx+PHP under Linux
Suppose we use PHP to implement a front-end controller, or to put it bluntly, a unified entry: send all PHP requests to the same file, and then implement routing by parsing “REQUEST_URI” in this file. Generally configured like this At this time, many tutorials will teach you to configure Nginx+PHP like this: server { listen 80; server_name foo.com; root /path; location / { index index.html index.htm index.php; if (!-e $request_filename) { rewrite ./index.php last; } } location ~ /.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME /path$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; }} There are a lot of mistakes, or at least bad smells, let’s see if you can find a few. It is necessary for us to understand the inheritance relationship of the instructions in the Nginx configuration file: The Nginx configuration file is divided into many blocks. The common ones are “http”, “server”, “location” and so on from the outside to the inside. The default inheritance relationship is from the outside to the inside, that is to say, the inner block will be obtained automatically The value of the outer block is used as the default value. Let’s start with the “index” directive In the problem configuration it…