Nginx and PHP-FPM traffic using UNIX sockets or TCP, and their configuration

Source: Internet
Author: User

Preface

There are two modes of communication between Nginx and FastCGI, one is TCP and the other is UNIX Socke. Each of the two methods have advantages and disadvantages, here first gives two kinds of configuration methods, and then the performance, security, and so on to make a summary.

TCP is using TCP ports to connect 127.0.0.1:9000
The socket is a socket/dev/shm/php-cgi.sock using UNIX domain sockets (many tutorials use the path/tmp, and the path/dev/shm is a tmpfs, much faster than disk), and when the server is not under pressure, TCP and socket is not very different, but when the pressure is more full, with the socket way, the effect is really good.

Configuration Guide

TCP configuration Mode

TCP communication configuration is simple, three steps can be done

The first step is to edit/etc/nginx/conf.d/your site profile (if you use the default profile, modify/etc/nginx/sites-available/default)

Modify the Fastcgi_pass parameter to 127.0.0.1:9000, like this:

1 2 3 4 5 6 7 Location ~ \.        PHP $ {index index. PHP index. HTML index. htm;        Include/etc/nginx/fastcgi_params;        FastCGI _pass 127.0.0.1:9000; Fastcgi_index index.        PHP;   Include Fastcgi_params; }

Step Two , edit the php-fpm configuration file/etc/php5/fpm/pool.d/www.conf

Modify the Listen parameter to 127.0.0.1:9000, like this:

1 Listen = 127.0.0.1:9000

Step three , restart PHP-FPM, restart Nginx

UNIX Socket Configuration method

Unix sockets are in fact strictly known as UNIX domain sockets, which is a widely used method of *nix system interprocess communication (IPC). With a file (typically. sock) as the unique identifier for the socket (descriptor), the two processes that need to communicate refer to the same socket descriptor file to establish a channel for communication.

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.