连接()失败(111:连接被拒绝),同时连接到上游

访问目录中的PHP文件时遇到502 Gateway错误( http://example.com/dev/index.php )。 日志只是说这个:

 2011/09/30 23:47:54 [error] 31160#0: *35 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "GET /dev/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "domain.com" 

我从来没有经历过这个。 什么是这种types的502 Gateway错误的解决scheme?

这是nginx.conf

 user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #} 

这听起来像你还没有启动并为Nginxconfiguration后端。 启动php-fpm并在http上下文中将以下内容添加到nginx.conf中:

 server { listen 127.0.0.1; server_name localhost; error_log /var/log/nginx/localhost.error_log info; root /var/www/localhost/htdocs; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; fastcgi_intercept_errors on; error_page 404 /error/404.php; } } 

这个答案只适用于那些得到如下错误的人:

connect()失败(111:连接被拒绝),同时连接到上游,客户端…. fastcgi:// [:: 1]:9000

重写你的nginxconfiguration使用ip,而不是dns。 例如, 127.0.0.1而不是localhost ,或从/ etc / hosts中删除ipv6别名。

也有这样的错误。 问题是我的抽象后端引用两个服务器。 php-fpm只是列表sockets…

 # Upstream to abstract backend connection(s) for php upstream php { server unix:/var/run/php5-fpm.sock; #server 127.0.0.1:9000; } server { [...] location ~ \.php$ { # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-fpm: fastcgi_pass php; fastcgi_index index.php; fastcgi_intercept_errors on; include fastcgi_params; } } 

在我的情况下,这个错误是php5.6-fpm服务的error_log文件的错误位置,因此php-fpm服务无法启动nginx无法连接到它 。 你可以在/etc/php/5.6/fpm/php.inifind它(你可以用你正在运行的版本replace5.6)。

我有同样的问题,并添加监听语句

 listen 127.0.0.1; 

为我工作。

有趣的是,我有其他的服务器块,运行相当愉快没有这个!