docker nginx connection refused while connecting to upstream

I use shiny server to build a web-app on port 3838, when i use nginx in my server it works well. But when I stop nginx on my server and try to use docker nginx, I find the site comes to a ‘502-Bad Gate Way’ error and nginx log shows:

2016/04/28 18:51:15 [error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, ...

I install docker-nginx by this command:

  • How to run HDFS cluster without DNS
  • Docker client not able to connect to docker host on VM on Windows 7
  • guacamole You do not have permission to access this connection"
  • Run apache tomcat server in docker container
  • Why am I getting this Nginx error about “No such file or directory”?
  • run “docker run” from crontab
  • sudo docker pull nginx
    

    My docker command line is something like (for clear i add some indent):

    sudo docker run --name docker-nginx -p 80:80 
        -v ~/docker-nginx/default.conf:/etc/nginx/conf.d/default.conf
        -v  /usr/share/nginx/html:/usr/share/nginx/html nginx
    

    I create a folder name ‘docker-nginx’ in my home dir, move my nginx conf file in this folder, and then remove my original conf in etc/nginx dir just in case.

    My nginx conf file looks like this:

    server {
        listen 80 default_server;
        # listen [::]:80 default_server ipv6only=on;
    
        root /usr/share/nginx/html;
        index index.html index.htm;
    
        # Make site accessible from http://localhost/
        server_name localhost;
    
        location / {
                proxy_pass http://127.0.0.1:3838/;
                proxy_redirect http://127.0.0.1:3838/ $scheme://$host/;
                auth_basic "Username and Password are required";
                auth_basic_user_file /etc/nginx/.htpasswd;
                # enhance the performance
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;
        }
    }
    

  • Why is /etc/hosts file empty in my docker container?
  • Docker volume with restart always option enabled
  • Unable to access jarfile - Docker on Elastic Beanstalk
  • How to see the logs of running application inside docker container?
  • accessing services outside kubernetes
  • Is there anyway to start rsyslogd without sudo access?
  • One Solution collect form web for “docker nginx connection refused while connecting to upstream”

    You have to define upstrem directive. Currently your nginx can not proxy to your web application.

    http://nginx.org/en/docs/http/ngx_http_upstream_module.html

    upstream backend {
        server backend1.example.com       weight=5;
        server backend2.example.com:8080;
        server unix:/tmp/backend3;
    
        server backup1.example.com:8080   backup;
        server backup2.example.com:8080   backup;
    }
    
    server {
        location / {
            proxy_pass http://backend;
        }
    }
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.