docker工nginxstream平衡器404

我有docker和nginx版本:nginx / 1.10.0(Ubuntu 16.04)

my nginx.conf user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 1024; # 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; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # 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/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } include /etc/nginx/tcpconf.d/*; #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; # } #} 

这是默认的nginx.conf,我添加了include /etc/nginx/tcpconf.d/*;

tcpconf.d包含1个文件:

 stream { upstream docker{ server localhost:8182; server localhost:8183; } server { listen 443; proxy_pass docker; } } 

所以,基本上我有docker上的glassfish 4服务器,当我启动8182端口上的容器我想Nginx的平衡请求端口8183(如果8182没有响应),并在相反的顺序。

这是完美的作品,除了一件事情,当我开始容器,glassfish服务器启动,并在此服务器上的Web应用程序也启动了。 Glassfish在1到5秒后启动,并在30秒 – 1分钟后启动Web应用程序,所以当glassfish启动时(例如在8182端口),nginx发送请求到这个端口,我得到404,因为glassfish启动了,但是web应用程序不启动,在这种情况下,我想在8183端口redirect,因为404不是我想看到的)

所以我的问题是如何告诉nginx不显示我404和尝试请求另一个端口?

是否有任何理由使用stream模块? 如果它是一个普通的http服务器,那么NGINX代理,然后使用普通的http {}和proxy_next_upstream来定义404错误的行为:

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream