[英]Nginx connection refused while connecting to Node.js upstream inside a Docker container
I have the following setup: 我有以下设置:
Docker container which has supervisord as the entry point, supervisord runs a Node.js process and Nginx proxy. Docker容器以supervisord作为入口点,supervisord运行Node.js进程和Nginx代理。 the Nginx port is exposed outside.
Nginx端口暴露在外面。
on the host machine, another Nginx is used for SSL termination and vhost routing / load balancing, its used as a proxy for the Docker containers. 在主机上,另一个Nginx用于SSL终止和vhost路由/负载平衡,它用作Docker容器的代理。
I'm experiencing some strange issues, where sometimes the Nginx server inside the Docker containers is reporting errors with connecting to the upstream Node.js servers. 我遇到了一些奇怪的问题,有时Docker容器内的Nginx服务器报告错误,连接到上游Node.js服务器。 seems like the HTTP requests are 200 so maybe it auto retries even if there's only one upstream?!
似乎HTTP请求是200,所以即使只有一个上游,也许它会自动重试?!
also, no sign of errors or crashes in the Node.js process stdout/stderr.. 此外,Node.js进程中没有错误或崩溃的迹象stdout / stderr ..
This are the errors that I see: 这是我看到的错误:
2014/07/31 12:48:54 [error] 15#0: *10 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.42.1, server: f074d2f4389f, request: "GET /users/me HTTP/1.1", upstream: "http://[::1]:3000/users/me", host: "xxx.xxx.com", referrer: "https://xxx.xxx.com/"
what can be the problem? 可能是什么问题?
This is the supervisord config files: 这是supervisord配置文件:
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=info ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
childlogdir=/var/log/supervisor/ ; where child log files will live"
and this file is included in other files: 这个文件包含在其他文件中:
[include]
files = /etc/supervisor/conf.d/supervisord.conf
[program:api]
command=node api-cluster.js
directory=/src
autorestart=true
startretries=100000000
stdout_logfile=/var/log/supervisor/api_stdout.log
stderr_logfile=/var/log/supervisor/api_stderr.log
[program:nginx]
command=/usr/sbin/nginx
autorestart=true
startretries=100000000
stdout_logfile=/var/log/supervisor/nginx_stdout.log
stderr_logfile=/var/log/supervisor/nginx_stderr.log"
and this is the Nginx conf file inside the Docker container: 这是Docker容器中的Nginx conf文件:
# -------------------------------------------------------------------
# Nginx configuraiton
# -------------------------------------------------------------------
worker_processes 4;
daemon off;
error_log stderr info;
pid /var/run/nginx.pid;
events {
#use epoll;
worker_connections 768;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main 'ip=\$http_x_real_ip [\$time_local] '
'"\$request" \$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent"' ;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
upstream app_proxy {
server localhost:3000; # nodejs server
}
server {
listen 80 deferred;
server_name \$hostname;
access_log /dev/stdout main;
location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|scripts/|views/|styles/|bower_components/|robots.txt|humans.txt|favicon.ico|home/|html|xml) {
root /src/web/public;
access_log off;
expires max;
}
location / {
proxy_redirect off;
#proxy_set_header X-Real-IP \$remote_addr;
#proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header Host \$http_host;
proxy_set_header X-NginX-Proxy true;
proxy_intercept_errors off;
proxy_pass http://app_proxy/;
}
}
}
Nginx connects to nodejs on the IPv6 loopback [::1]. Nginx连接到IPv6 loopback [:: 1]上的nodejs。 nodejs is probably just listening on IPv4.
nodejs可能只是在侦听IPv4。
Try setting 尝试设置
upstream api {
server 127.0.0.1:5000;
}
Nginx connects to nodejs on the IPv6 loopback [::1]. Nginx连接到IPv6 loopback [:: 1]上的nodejs。 nodejs is probably just listening on IPv4.
nodejs可能只是在侦听IPv4。
need to set 需要设定
upstream api {
server 127.0.0.1:5000;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.