php-fpm nginx配置文件 处理 Permission denied 错误

来源:互联网 发布:知乎为什么封号 编辑:程序博客网 时间:2024/05/22 02:19

配置php-fpm脚本(php-fpm.conf):

[www]    131     132 ; Per pool prefix    133 ; It only applies on the following directives:    134 ; - 'access.log'    135 ; - 'slowlog'    136 ; - 'listen' (unixsocket)    137 ; - 'chroot'    138 ; - 'chdir'    139 ; - 'php_values'    140 ; - 'php_admin_values'    141 ; When not set, the global prefix (or /usr/local/php) applies instead.    142 ; Note: This directive can also be relative to the global prefix.    143 ; Default Value: none    144 ;prefix = /path/to/pools/$pool    145     146 ; Unix user/group of processes    147 ; Note: The user is mandatory. If the group is not set, the default user's group    148 ;       will be used.    149 user = dyh    150 group = dyh    151     152 ; The address on which to accept FastCGI requests.    153 ; Valid syntaxes are:    154 ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on    155 ;                            a specific port;    156 ;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on    157 ;                            a specific port;    158 ;   'port'                 - to listen on a TCP socket to all IPv4 addresses on a    159 ;                            specific port;    160 ;   '[::]:port'            - to listen on a TCP socket to all addresses    161 ;                            (IPv6 and IPv4-mapped) on a specific port;    162 ;   '/path/to/unix/socket' - to listen on a unix socket.    163 ; Note: This value is mandatory.    164 listen = /tmp/php-fpm.sock    165 ;listen = 127.0.0.1:9000    166     167 ; Set listen(2) backlog.    168 ; Default Value: 65535 (-1 on FreeBSD and OpenBSD)    169 ;listen.backlog = 65535    170     171 ; Set permissions for unix socket, if one is used. In Linux, read/write    172 ; permissions must be set in order to allow connections from a web server. Many    173 ; BSD-derived systems allow connections regardless of permissions.    174 ; Default Values: user and group are set as the running user    175 ;                 mode is set to 0660    176 ;listen.owner = www    177 ;listen.group = www    178 listen.mode = 0666


当此处listen配置成unix socket时,在nginx中也需配置成相同的配置

配置为unix socket时需将 listen.mode = 0666 避免在使用nginx时出现 (connect() to unix:/tmp/php-fpm.sock failed (13: Permission denied))错误

nginx中fast cgi配置可用如下:

     13     location ~ \.php$ {     14 #        fastcgi_pass 127.0.0.1:9000;     15         fastcgi_pass unix:/tmp/php-fpm.sock;     16         fastcgi_index index.php;     17         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;     18         include        fastcgi_params;     19     }

其中fastcgi_pass 需要与 php-fpm.conf中一致

配置完成后去php目录启动 php-fpm,nginx中启动nginx.

原创粉丝点击