Configure php-fpm and nginx communication on the CentOS Server
- <Spanstyle = "font-size: 18px;"> The following is the default nginx configuration file:
- Server {
- Listen80;
- Server_namelocalhost;
- # Charsetkoi8-r;
- # Access_loglogs/host. access. logmain;
- Location /{
- Root/usr/share/nginx/html;
- Indexindex.htmlindex.htm;
- }
- # Error_page404/404.html;
- # Redirectservererrorpagestothestaticpage/50x.html
- #
- Error_page500502503504/50x.html;
- Location =/50x.html {
- Roothtml;
- }
- # ProxythePHPscriptstoApachelisteningon127.0.0.1: 80
- #
- # Location ~ \. Php $ {
- # Proxy_passhttp: // 127.0.0.1;
- #}
- # PassthePHPscriptstoFastCGIserverlisteningon127.0.0.1: 9000
- #
- # Location ~ \. Php $ {
- # Roothtml;
- # Fastcgi_pass127.0.0.1: 9000;
- # Fastcgi_indexindex.php;
- # Fastcgi_paramSCRIPT_FILENAME/scripts $ fastcgi_script_name;
- # Define defastcgi_params;
- #}
- # Denyaccessto. htaccessfiles, ifApache 'sdocumentroot
- # Concurswithnginx 'sone
- #
- # Location ~ /\. Ht {
- # Denyall;
- #}
- } </Span>
A location matches a url.
Match the corresponding url to the corresponding location, and then process the request.
The default root is/usr/share/nginx/html, that is, the request is forwarded to the corresponding directory for processing.
But there is no way to Parse Files that match php.
Here we use php-fpm, which is a class library of fastcgi in php.
When a request with a. php end is matched, the request is forwarded to fastcgi for processing.
Server_name remains entangled for a long time. When I have two users a and B in the same operating system, both of them have their own root directories for access, and both have their own server configured. However, nginx configuration files work globally. Which directory does c access when accessing this server in the lan?
Later, my brother told me.
Generally, when nginx is configured on an online website, server_name is the domain name. nginx naturally knows how to transfer it based on different domain names.
If the ip address is used for access in the LAN, if there are two servers, you can configure one. When the ip address is used for access, you can jump to a directory by default.
You can configure a server when you are online.
By default, this directory is requested and forwarded with fastccgi.
When nginxis configured, a question is found. The root directory at the end of the. html file can be accessed normally, and the static file at the End of. php cannot be accessed.
Later, it was discovered that, during configuration, the root variable was changed to a local variable, resulting in no root found when matching the PHP file. Naturally, the file to be accessed cannot be found.
The final configuration is as follows: