Configure php-fpm and nginx communication on the CentOS Server

Source: Internet
Author: User
Tags centos server

Configure php-fpm and nginx communication on the CentOS Server

  1. <Spanstyle = "font-size: 18px;"> The following is the default nginx configuration file:
  2. Server {
  3. Listen80;
  4. Server_namelocalhost;
  5. # Charsetkoi8-r;
  6. # Access_loglogs/host. access. logmain;
  7. Location /{
  8. Root/usr/share/nginx/html;
  9. Indexindex.htmlindex.htm;
  10. }
  11. # Error_page404/404.html;
  12. # Redirectservererrorpagestothestaticpage/50x.html
  13. #
  14. Error_page500502503504/50x.html;
  15. Location =/50x.html {
  16. Roothtml;
  17. }
  18. # ProxythePHPscriptstoApachelisteningon127.0.0.1: 80
  19. #
  20. # Location ~ \. Php $ {
  21. # Proxy_passhttp: // 127.0.0.1;
  22. #}
  23. # PassthePHPscriptstoFastCGIserverlisteningon127.0.0.1: 9000
  24. #
  25. # Location ~ \. Php $ {
  26. # Roothtml;
  27. # Fastcgi_pass127.0.0.1: 9000;
  28. # Fastcgi_indexindex.php;
  29. # Fastcgi_paramSCRIPT_FILENAME/scripts $ fastcgi_script_name;
  30. # Define defastcgi_params;
  31. #}
  32. # Denyaccessto. htaccessfiles, ifApache 'sdocumentroot
  33. # Concurswithnginx 'sone
  34. #
  35. # Location ~ /\. Ht {
  36. # Denyall;
  37. #}
  38. } </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.