【问题标题】:Nginx connect() failed errorNginx connect() 失败错误
【发布时间】:2013-03-28 23:41:56
【问题描述】:

不知道为什么每次打开页面都会出现这个错误:

2013/04/06 17:52:19 [error] 5040#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:8080"

【问题讨论】:

  • 显示配置文件的相关部分可能会有所帮助。

标签: php nginx server


【解决方案1】:

我发现我在 Debian Jessie (8.3) 实例上的 Docker 中运行 PHP7 时遇到了同样的问题。

  • 运行命令“ps -aux”显示 php-fpm 没有运行
  • 运行 'php-fpm -D' 将其作为去守护进程启动。
  • 重新运行 'ps -aux' 表明 php-fpm 确实在运行
  • 刷新我的测试页面显示服务器 PHP 信息。

在我的 start.sh 脚本中添加了“php-fpm -D”,以便每次加载容器时都会启动。

希望这对某人有所帮助。

【讨论】:

    【解决方案2】:

    我解决了,是配置文件问题,我补充道:

    location ~ .php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
    

    【讨论】:

    • 在某些情况下fastcgi_pass 127.0.0.1:9000; 存在于服务器块中并导致此错误,在这种情况下您需要将其更改为fastcgi_pass unix:/var/run/php5-fpm.sock;
    • 这是因为 php5-fpm 现在附带在 /etc/php5/fpm/pool.d/www.conf 中启用的 Unix 套接字 listen = /var/run/php5-fpm.sock,而不是 TCP 套接字 listen = 127.0.0.1:9000。这通常会快一点。 (用于谷歌搜索)ubuntu 14.04 nginx php5-fpm 502 Bad Gateway。我感觉在不久的将来会有很多人需要这个。有很多教程都使用旧套接字。
    • 谢谢你,@KamilZieliński!更改为 fastcgi_pass unix:/var/run/php5-fpm.sock; 修复了我的错误。
    • 在我的情况下(centos 7)我必须使用fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;。错误日志是你的朋友:sudo tail -20 /var/log/nginx/error.log
    【解决方案3】:

    使用 fastcgi_pass unix:/var/run/php5-fpm.sock;只有 nginx 和 php 安装相同的服务器。如果 nginx 和 php 安装在其他服务器上,你必须使用 fastcgi_pass ip server:port;

    【讨论】:

      【解决方案4】:

      对我来说,问题是我的 php-fpm 服务没有运行。您可以通过运行来检查它:

      service php-fpm status
      

      并通过运行启动它

      service php-fpm start
      

      有时 php-fpm 可能会破坏正在运行的实例,从而阻止重新启动。此命令是清除它们并重新启动 php-fpm 的一种干净方法

      killall -9 php-fpm; service php-fpm restart
      

      【讨论】:

      • 对我来说重新启动 php-fpm,我需要执行以下操作: touch /var/run/php5-fpm.sock && chmod 777 /var/run/php5-fpm.sock
      【解决方案5】:

      如前所述更新您的配置:

      location ~ .php$ {
      try_files $uri =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
      }
      

      但不要忘记更新后重启nginx服务器和php-fpm

      sudo /etc/init.d/nginx restart
      sudo /etc/init.d/php-fpm restart
      

      【讨论】:

      • 这属于给定答案下方的评论。有点像您只是想获得支持。是的。重新启动 nginx 是必要的,但大多数人都会知道这一点,如果他们不知道,他们会在一直向下滚动之前在评论中看到它。
      猜你喜欢
      • 1970-01-01
      • 2011-02-20
      • 2016-06-07
      • 2013-09-01
      • 2010-12-16
      • 2016-08-12
      • 2014-02-16
      • 2016-11-13
      • 2017-05-17
      相关资源
      最近更新 更多