Configure the communication between php-fpm and nginx in centos, and centosphp-fpm

Source: Internet
Author: User

Configure the communication between php-fpm and nginx in centos, and centosphp-fpm

<Span style = "font-size: 18px;"> The following is the default nginx configuration file: server {listen 80; server_name localhost; # charset koi8-r; # access_log logs/host. access. log main; location/{root/usr/share/nginx/html; index index.html index.htm;} # error_page 404/404 .html; # redirect server error pages to the static page/50x.html # error_page 500 502 503 504/50 x.html; location =/50x.html {root html;} # proxy the PHP script S to Apache listening on 127.0.0.1: 80 # location ~ \. Php $ {# proxy_pass http: // 127.0.0.1; #}# pass the PHP scripts to FastCGI server listening on 127.0.0.1: 9000 # location ~ \. Php $ {# root html; # fastcgi_pass 127.0.0.1: 9000; # fastcgi_index index. php; # fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; # include fastcgi_params; #}# deny access. htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\. Ht {# deny all ;#}</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:


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.