What is the communication between Nginx and PHP-FPM?

Source: Internet
Author: User
server {root /srv/www;location / {            index  index.html index.htm;        }location ~ \.php$ {            fastcgi_pass   127.0.0.1:9000;            fastcgi_param SCRIPT_FILENAME /src/www$fastcgi_script_name;            include        fastcgi_params;        }}

In the directory/srv/www there are index.html index.php two files, Access localhost/index.html, localhost to display the normal/srv/www/ Index.html the contents of the page, but accessing the index.php file does not Found, do you know what's going on? In this case, is not nginx should be sent to the/srv/www/index.php file to listen to the PHP parser in 127.0.0.1:9000, and then through its parsing to return the contents of the parser to the client? I do not know where the problem, I hope to help answer the next

Reply content:

server {root /srv/www;location / {            index  index.html index.htm;        }location ~ \.php$ {            fastcgi_pass   127.0.0.1:9000;            fastcgi_param SCRIPT_FILENAME /src/www$fastcgi_script_name;            include        fastcgi_params;        }}

In the directory/srv/www there are index.html index.php two files, Access localhost/index.html, localhost to display the normal/srv/www/ Index.html the contents of the page, but accessing the index.php file does not Found, do you know what's going on? In this case, is not nginx should be sent to the/srv/www/index.php file to listen to the PHP parser in 127.0.0.1:9000, and then through its parsing to return the contents of the parser to the client? I do not know where the problem, I hope to help answer the next

Estimated to be your nginx fpm configuration problem.
My side of this, has been used a number of sites:

server {        listen   80; ## listen for ipv4; this line is default and implied        root /www/web;        index index.html index.htm index.php;        location / {                # First attempt to serve request as file, then                # as directory, then fall back to displaying a 404.                try_files $uri $uri/ /index.html;                # Uncomment to enable naxsi on this location                # include /etc/nginx/naxsi.rules        }        location ~ \.php$ {                fastcgi_split_path_info ^(.+\.php)(/.+)$;                fastcgi_pass unix:/var/run/php5-fpm.sock;                fastcgi_index index.php;                include fastcgi_params;        }}

Look at the FPM error log and locate the problem in minutes!

location / {    index  index.php index.html index.htm;}

The first file needs to be identified with index.php in index

Here's the problem:

server {root /srv/www;#srv目录location / {            index  index.html index.htm;        }location ~ \.php$ {            fastcgi_pass   127.0.0.1:9000;            fastcgi_param SCRIPT_FILENAME /src/www$fastcgi_script_name; #src目录            include        fastcgi_params;        }}

Other than that:
The following section is best written in this way:

location ~ \.php$ {        fastcgi_split_path_info ^(.+\.php)(/.+)$;        fastcgi_pass 127.0.0.1:9000;#        fastcgi_pass unix:/var/run/php5-fpm.sock;#这行和上面一行二选一。        fastcgi_index index.php;        include fastcgi_params;}
  • 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.