php-fpm sock文件權限設置

在編譯php-fpm時,若沒有指定fpm用戶,在配置文件中也沒有指定用戶,則sock文件會由root(啓動php-fpm的用戶)建立,其權限是srw-rw----php

而nginx通常由nginx用戶啓動,會致使沒法讀取sock文件,形成nginx返回502錯誤。python

nginx日誌會記錄錯誤以下: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用戶web

; 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便可less

注:sock文件存放在/dev/shm目錄下,
此目錄下將sock文件放在內存裏面,有助於性能提高socket

相關文章
相關標籤/搜索