php7 - Configuration issues with fastcgi_pass in Nginx
某草草
某草草 2017-05-16 17:18:04
0
1
637

When configuring nginx, the configuration problem of fastcgi_pass is as follows:

    location ~ \.php$ {
        root           /home/wwwroot;
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
        #fastcgi_pass  unix:/tmp/php-cgi.sock;
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

Mainly about fastcgi_pass parameters,

#fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
#fastcgi_pass  unix:/tmp/php-cgi.sock;

What is the difference between these two methods? Which one should be used in php7?

某草草
某草草

reply all(1)
大家讲道理

There are two ways of inter-process communication between Nginx and PHP-FPM, one is TCP and the other is UNIX Domain Socket.
TCP is IP plus port, which can be used across servers. UNIX Domain Socket does not go through the network and can only be used In the scenario where Nginx and PHP-FPM are both on the same server. Which one to use depends on your PHP-FPM configuration:
Method 1:
php-fpm.conf: listen = 127.0.0.1:9000
nginx.conf: fastcgi_pass 127.0 .0.1:9000;
Method 2:
php-fpm.conf: listen = /tmp/php-fpm.sock
nginx.conf: fastcgi_pass unix:/tmp/php-fpm.sock;
where php-fpm.sock It is a file, generated by php-fpm, the type is srw-rw----.

UNIX Domain Socket can be used for two unrelated processes. It is a widely used IPC mechanism at present. For example, the communication between X Window server and GUI program is through UNIX Domain Socket. This communication method occurs in the system kernel. It will not spread in the network. Both UNIX Domain Socket and long connections can avoid the problem of too many TIME_WAIT connections caused by frequently creating TCP short connections. For two programs communicating between processes, the process of UNIX Domain Socket will not go to TCP. Layer, communicate directly in the form of files and stream socket. If it is TCP Socket, you need to go to the IP layer. For different servers, TCP Socket has more steps.

UNIX Domain Socket:
Nginx <=> socket <=> PHP-FPM
TCP Socket (local loopback):
Nginx <=> socket <=> TCP/IP <=> socket <=> PHP-FPM
TCP Socket (Nginx and PHP-FPM are on different servers):
Nginx <=> socket <=> TCP/IP <=> Physical layer<=&gt ; Router<=> Physical layer<=> TCP/IP <=> socket <=> PHP-FPM

Like the mysql command line client, there are two similar ways to connect to the mysqld service:
Use Unix Socket to connect (default):
mysql -uroot -p --protocol=socket --socket=/tmp/mysql. sockmysql -uroot -p --protocol=socket --socket=/tmp/mysql.sock
使用TCP连接:
mysql -uroot -p --protocol=tcp --host=127.0.0.1 --port=3306Use TCP connection:

mysql -uroot -p --protocol=tcp --host=127.0.0.1 --port=3306🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template