php与nginx通讯方式,[Linux]PHP-FPM与NGINX的两种通讯方式

一、通过监听TCP端口通讯

php-fpm.d/www.conf

; The address on whichto accept FastCGI requests.

; Valid syntaxes are:

;‘ip.add.re.ss:port‘ -to listen on a TCP socket to a specific IPv4 address on

; a specific port;

;‘[ip:6:addr:ess]:port‘ -to listen on a TCP socket to a specific IPv6 address on

; a specific port;

;‘port‘ -to listen on a TCP socket to all addresses

; (IPv6 and IPv4-mapped) 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

nignx.conf

location ~\.php {

root/lroot/wwwroot/test;

fastcgi_pass127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_split_path_info^(.+\.php)(.*)$;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

二、通过unix socket进程间通讯

先选定一个目录创建一个空.sock文件,例如/run/php-fpm.sock(注意不应选用/tmp目录),再进行配置

php-fpm.d/www.conf

1.设置通讯方式

; The address on whichto accept FastCGI requests.

; Valid syntaxes are:

;‘ip.add.re.ss:port‘ -to listen on a TCP socket to a specific IPv4 address on

; a specific port;

;‘[ip:6:addr:ess]:port‘ -to listen on a TCP socket to a specific IPv6 address on

; a specific port;

;‘port‘ -to listen on a TCP socket to all addresses

; (IPv6 and IPv4-mapped) on a specific port;

;‘/path/to/unix/socket‘ -to listen on a unix socket.

; Note: This value is mandatory.

listen= /run/php-fpm.sock

2.设置创建.sock文件的访问权限,以便nginx进程能够访问php-fpm创建的.sock

; Unix user/group of processes

; Note: The user is mandatory. If the group is not set, the default user‘s group

; will be used.

user=nginx

group= nginx

; Set permissions for unix socket, if one is used. In Linux, read/write; permissions must be setinorder to allow connections from a web server. Many

; BSD-derived systems allow connections regardless of permissions.

; Default Values: user and group are set as the running user

; mode is set to0660listen.owner=nginx

listen.group=nginx

listen.mode= 0660

nignx.conf

location ~\.php {

root/lroot/wwwroot/test;

fastcgi_pass unix:/run/php-fpm.sock;

fastcgi_index index.php;

fastcgi_split_path_info^(.+\.php)(.*)$;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值