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:

  • Running .Net on Docker
  • Docker bridge and Falcon gunicorn
  • Varnish + Nginx proxy configuration on plesk
  • Does docker support command aliases similar to Git aliases?
  • Unable to start Docker Container in Bluemix
  • Sending sigstop and sigcont to docker containers
  • 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;
        }
    }
    

  • docker build of Dockerfile fails
  • Is the data in unbound docker container volumes committed to the image?
  • Docker container fails to connect to second container when running under Compose
  • How to mount volumes to global volume in Docker Swarm and bundle
  • Failing to delete Docker's images after terminating the container
  • Docker, How can I locate the image files after pulling [duplicate]
  • 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.