Explain in detail how to configure Nginx+PHP correctly
Suppose we implement a front-end controller with PHP, 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. 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, which means that the inner blocks 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 is defined in…