不积跬步,何以至千里

导航

解决:connect() to unix:/run/php/php8.1-fpm.sock failed (13: Permission denied)

装好了nginx与php8.1-fpm,两都能正常运行,但PHP文件不能正常显示,查看nginx的error.log,有这样的记录:

connect() to unix:/run/php/php8.1-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 192.168.0.114, server: localhost, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock:", host: "192.168.0.11"

原因是 php8.1-fpm 的apt安装使用了缺省用户www-data,nginx的apt安装使用了缺省用户nginx,/run/php/php8.1-fpm.sock的所有者是www-data, nginx用户无权访问,导致以上报错。

查看nginx的缺省配置文件:

 1 user  nginx;
 2 worker_processes  auto;
 3 
 4 error_log  /var/log/nginx/error.log notice;
 5 pid        /var/run/nginx.pid;
 6 
 7 
 8 events {
 9     worker_connections  1024;
10 }
11 
12 
13 http {
14     include       /etc/nginx/mime.types;
15     default_type  application/octet-stream;
16 
17     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
18                       '$status $body_bytes_sent "$http_referer" '
19                       '"$http_user_agent" "$http_x_forwarded_for"';
20 
21     access_log  /var/log/nginx/access.log  main;
22 
23     sendfile        on;
24     #tcp_nopush     on;
25 
26     keepalive_timeout  65;
27 
28     #gzip  on;
29 
30     include /etc/nginx/conf.d/*.conf;
31 }

把第一条user nginx改成user  www-data即可。

记得重启nginx使配置生效。

 

posted on 2022-05-01 15:33  环保发动机  阅读(3457)  评论(0编辑  收藏  举报