【问题标题】:502 Bad Gateway in nginx/1.4.6 (Ubuntu14 Digital Ocean)nginx/1.4.6 (Ubuntu14 Digital Ocean) 中的 502 Bad Gateway
【发布时间】:2017-01-26 12:11:54
【问题描述】:

我正在安装 PHP7.0、Nginx1.4.6 并配置如下,但我遇到了很多错误。

sudo nano /etc/php/7.0/fpm/pool.d/www.conf

#listen = /run/php/php7.0-fpm.sock
#listen = /var/run/php/php7.0-fpm.sock
listen = 127.0.0.1:9000
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

server {
#       listen 80 default_server;
        listen 80;
        listen [::]:80 default_server ipv6only=on;

        location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_index index.php;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

让我们看看日志:

2017/01/26 03:33:54 [error] 2976#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 96.9.77.42, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "128.199.133.1$
2017/01/26 03:33:55 [error] 2976#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 96.9.77.42, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "128.199.133.1$
2017/01/26 03:33:55 [error] 2976#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 96.9.77.42, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "128.199.133.1$

【问题讨论】:

  • 服务 php7.0-fpm 重启
  • 多次重启服务器但还是一样
  • 不监听 9000 端口 从 127.0.0.1 移除 9000;
  • 在 www.conf 或 sites-enable 中?
  • 在 www.conf 中试试

标签: nginx


【解决方案1】:

您可能需要将listen.allowed_clients 设置为127.0.0.1 并评论groupuser 部分

# only localhost can connect to PHP-FPM
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
# listen.owner = www-data
# listen.group = www-data

然后重启php-fpm服务,检查是否在9000端口上运行

【讨论】:

  • root@ubuntu-512mb-sgp1-01:~# netstat -ntlp | grep LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1443/sshd tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1505/mysqld tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2760/nginx tcp6 0 0 :::22 :::* LISTEN 1443/sshd tcp6 0 0 :::80 :::* LISTEN 2760/nginx
  • 没有php-fpm进程在运行?
  • 是的,我找不到它,但是当我 sudo php7.0-fpm restart 它发送给我 php7.0-fpm start/running, process 2779
  • 我需要重启服务器吗?
  • 运行,sudo restart php7.0-fpm
猜你喜欢
  • 2023-03-20
  • 2017-06-05
  • 1970-01-01
  • 2020-05-15
  • 2018-04-23
  • 2021-02-24
  • 1970-01-01
  • 2022-08-16
  • 2020-08-01
相关资源
最近更新 更多