在PHP-FPM(FastCGI Process Manager)配置中,listen 参数用于指定PHP-FPM监听的地址和端口。这个参数通常设置在 php-fpm.conf 或者其子配置文件(如 www.conf)中。以下是一些常见的设置示例:
如果你希望PHP-FPM通过Unix套接字与Web服务器通信,可以使用以下配置:
listen = /var/run/php-fpm/php-fpm.sock
或者,如果你希望使用命名管道(FIFO):
listen = /tmp/php-fpm.sock
如果你希望PHP-FPM通过TCP/IP端口与Web服务器通信,可以使用以下配置:
listen = 127.0.0.1:9000
或者,如果你希望监听所有网络接口:
listen = 0.0.0.0:9000
你也可以同时配置多个监听地址,以便PHP-FPM可以同时通过Unix套接字和TCP/IP端口与Web服务器通信:
listen = /var/run/php-fpm/php-fpm.sock
listen = 127.0.0.1:9000
listen = [::1]:9000
php-fpm.conf:通常是PHP-FPM的主配置文件。www.conf:通常包含与Web服务器(如Nginx或Apache)相关的特定配置。以下是一个完整的 www.conf 示例,展示了如何配置 listen 参数:
; Start a new pool named 'www'.
[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 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;
; 'unix:/path/to/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php-fpm/php-fpm.sock
; Set listen.owner, listen.group and listen.mode to the values necessary for
; your application to talk to PHP-FPM without umask.
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names.
; It is a good setup if your PHP-FPM and web server are not running as root.
; listen.allowed_clients = user1,user2
在修改配置文件后,记得重启PHP-FPM服务以使更改生效:
sudo systemctl restart php-fpm
或者,如果你使用的是其他系统初始化系统,可以使用相应的命令来重启服务。
通过以上配置,你可以根据需要设置PHP-FPM的监听地址和端口。