Connect to nginx through socket to optimize PHP-FPM Performance

Source: Internet
Author: User
Tags unix domain socket

Nginx is connected to FastCGI through HTTP. in Linux, another faster method is to use Unix domain socket. The following describes this method:

The following must be modified:

/Usr/local/PHP/etc/php-fpm.conf

Change to: <value name = "listen_address">/dev/SHM/PHP. Socket </value>

Specifically,/dev/SHM/PHP. socket is the socket file used for nginx to communicate with PHP-FPM. The name and path are arbitrary. Put the socket in/dev/SHM, And/dev/SHM is a tmpfs, which is much faster than the disk.

2./usr/local/PHP/sbin/PHP-FPM restart

Restart PHP-FTM to generate the newly specified/dev/SHM/PHP. socket.

3. chown Nobody. Nobody/dev/SHM/PHP. Socket

Here, the nobody user is a UNIX user used by nginx and PHP-FPM. If you are not a nobody, modify it as appropriate.

4. modify the configuration of the server segment in nginx that needs to connect to PHP-FPM, and change the HTTP Method to the socket method.

Location ~ . * \. (PhP | PhP5 )? $

{

# Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_pass Unix:/dev/SHM/PHP. Socket;

Fastcgi_index index. php;

Include FastCGI. conf;

}

5. Restart nginx:./nginx-s reload.

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.