在编译php-fpm时,若没有指定fpm用户,在配置文件中也没有指定用户,则sock文件会由root(启动php-fpm的用户)创建,其权限是srw-rw----
。
而nginx一般由nginx用户启动,会导致无法读取sock文件,造成nginx返回502错误。
nginx日志会记录错误如下:
2018/09/12 17:06:17 [crit] 30735#0: *1 connect() to unix:/dev/shm/php-cgi.sock failed (13: Permission denied) while connecting t o upstream......
解决办法是在配置文件中指定listen用户
; Set permissions for unix socket, if one is used. In Linux, read/write ; permissions must be set in order 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 to 0666 listen.owner = fcgi listen.group = wwwgroup listen.mode = 0666
改完后重启php-fpm即可
注:sock文件存放在/dev/shm目录下,
此目录下将sock文件放在内存里面,有助于性能提升
原文地址:https://www.cnblogs.com/xzlive/p/9636220.html
时间: 2024-10-27 13:27:16