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.