nginx 常见错误

545 阅读1分钟

1、

2019/11/06 21:15:35 [error] 19095#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /install.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxx.xxx.xxx.xxx"

nginx配置文件

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

php-fpm配置文件

$ vim /etc/php-fpm.d/www.conf

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php7-fpm.sock

将nginx配置文件中的

fastcgi_pass   127.0.0.1:9000;

修改为

fastcgi_pass   unix:/var/run/php-fpm/php7-fpm.sock;

2、

2019/11/06 21:24:36 [crit] 20985#0: *16 connect() to unix:/var/run/php-fpm/php7-fpm.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /install.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php7-fpm.sock:", host: "xxx.xxx.xxx.xxx"

nginx配置文件

user  nginx;

php-fpm配置文件

; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 511

; 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
listen.group = www
listen.mode = 0660

将nginx配置文件中的用户和php-fpm中保持一致

user  www;