Nginx unix:/tmp/php-cgi.sock

在配置Nginx和php-fpm的时候,我们有时候需要修改通信方式

默认一般是tcp的方式,也就是我们在php-fpm配置文件看到的

1
2
3
4
5
6
7
8
9
10
11
12
[www]

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
...

有时候我们需要用socket的方式,因为unix socket比tcp快

因此我们要改成

1
2
3
4
5
6
7
8
9
10
11
12
[www]

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
; listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-cgi.sock

同样nginx.conf里面也要修改相应内容

1
2
3
4
5
6
```nginx
location ~ [^/]\.php(/|$) {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-cgi.sock;
fastcgi_index index.php;
}

重启php-fpm、nginx服务即可

如何重启php-fpm
如何重启Nginx
配置Nginx、php-fpm可能遇到的问题

坚持原创技术分享,谢谢鼓励我继续创作!