Nginx 502 Gateway Error with docker

Posted August 16, 2017 19.7k views
NginxDockerUbuntu 16.04

I created the Docker 17.06.0-ce on 16.04 Droplet and composed hospitalrun-server docker container. I done DNS config, installed nginx and configured ufw.

Docker compose file is here. I run my docker container with,

$ cd ~/works/hospitalrun-server
$ docker-compose up --build -d

My dockers are healthy

docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                                                  NAMES
53704c8cba8d        hospitalrun_nginx      "/bin/sh -c /etc/n..."   2 hours ago         Up 2 hours          80/tcp,>443/tcp,>8080/tcp   hospitalrunserver_nginx_1
ea3888970ac8        hospitalrun            "/bin/sh -c ./entr..."   2 hours ago         Up 2 hours          3000/tcp                                               hospitalrun
fd8ad7612a5c        hospitalrun_logstash   "/usr/local/bin/do..."   15 hours ago        Up 2 hours          5044/tcp, 9600/tcp                                     logstash_hr
e837f6ba143e        couchdb:1.6            "tini -- /docker-e..."   15 hours ago        Up 2 hours>5984/tcp                                 couchdb_hr

netstat’ command’s output is

$ netstat -plutn 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0    *               LISTEN      17601/nginx -g daem
tcp        0      0    *               LISTEN      1368/sshd       
tcp6       0      0 :::80                   :::*                    LISTEN      17601/nginx -g daem
tcp6       0      0 :::22                   :::*                    LISTEN      1368/sshd       
tcp6       0      0 :::8055                 :::*                    LISTEN      4012/docker-proxy
tcp6       0      0 :::443                  :::*                    LISTEN      4031/docker-proxy
tcp6       0      0 :::5985                 :::*                    LISTEN      3364/docker-proxy

My nginx configuration file is

worker_processes 1;

events { worker_connections 1024; }

http {
    upstream website {

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        gzip_types text/plain text/css application/json application/x-javascript
                   text/xml application/xml application/xml+rss text/javascript;

        location / {
            proxy_pass http://website;
            #include /etc/nginx/proxy_params;
            #include /etc/nginx/mime.types;

Each and are produced the 502 gateway error. My nginx error’ part is

2017/08/16 13:06:32 [error] 17602#17602: *9 connect() failed (111: Connection refused) while connecting to upstream, client:, server:, request: "GET / HTTP/1.1", upstream: "", host: ""

I tested successfully hospitalrun-server in local machine but i get error in my droplet.

Can you offer any guide or tutorial for production environment (specifically docker)? Thanks for your time and interest


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi, sorry you didn’t receive any answers on your question, but I’m glad to see that you were able to resolve the issue!