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:

  • Cannot connect Npgsql to Postgres DB running on Docker
  • docker-compose image export and import
  • Docker COPY behaving inconsistently
  • Link images on Docker Hub
  • Restore a Postgresql database into a Docker container so when Postgres starts up the DB is in place
  • SBT Docker ADD file not found
  • 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_redirect $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;

  • File mounted as docker volume becomes corrupt when saved outside docker
  • Docker EXPOSE vs command line -p option (boot2docker)
  • Can't restart a docker container that was created and worked via visual studio 2015's build
  • How to ask docker to pull from private repository when building
  • Docker - Initialize mysql database with schema
  • How to use local docker images in convox?
  • 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.

    upstream backend {
        server       weight=5;
        server unix:/tmp/backend3;
        server   backup;
        server   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.