一般systemctl在启动nginx和php-fpm的时候默认是以root权限执行的,为了安全起见,nginx和php-fpm会在启动的配置文件中指明他们所需的权限,如nginx的用户文件在/etc/nginx/nginx.conf中,比如下:
默认是nginx用户
user nginx; #这里指明了用户默认nginx
worker_processes 1;
......
http {
.......
}
php-fpm所需的权限一般在pool里面指定比如:/etc/php/7.2/fpm/pool.d/www.conf 里面
listen = /run/php/php7.2-fpm.sock
....
; 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 0660
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
这里php-fpm的监听地址是/run/php/php7.2-fpm.sock
默认是www-data用户,因此我们查看其权限会发现
srw-rw---- 1 www-data www-data 0 Apr 2 03:38 /run/php/php7.2-fpm.sock
由于/run/php/php7.2-fpm.sock的用户是www-data而nginx的用户是nginx,用户名字不匹配造成权限问题
就出现了 unix:/run/php/php7.2-fpm.sock failed (13: Permission denied)
解决方法是把nginx的权限改为www-data
user www-data;
worker_processes 1;
......
http {
.......
}
......