GreenGodot
GreenGodot

Reputation: 6773

502 Bad Gateway error using Docker-Compose and nginx-proxy

I am new to nginx and am trying to set up linked DOcker containers using Docker-Compose.

Based off of a tutorial here and jwilder's documentation here, I am attempting to deploy an Nginx proxy on top of my Django container. The docker-compose.yml is structured like so:

  build: .
  command:  bash -c "sleep 5 && python -u reroute/manage.py runserver 0.0.0.0:8081"
  volumes:
    - .:/code
  environment:
    - PYTHONUNBUFFERED=0
    - VIRTUAL_HOST=site1.com
    - VIRTUAL_PORT=8081
  ports:
    - "8081:8081"
  links:
    - db

db:
  image: postgres:latest
  environment:
    POSTGRES_PASSWORD: xxxxxx
    POSTGRES_USER: xxxxxx
  ports:
    - "5432"
  volumes:
    - ./backups:/home/backups

nginx:
  image: jwilder/nginx-proxy
  restart: always
  volumes:
    - /var/run/docker.sock:/tmp/docker.sock
  ports:
    - "80:80"

And the configuration in Nginx's .conf file looks like so:

server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    listen 80;
    access_log /var/log/nginx/access.log vhost;
    return 503;
}
upstream urls.mapquest.com {
                ## Can be connect with "bridge" network
            # googleadtrafficredirect_web_1
            server 172.17.0.4:8081;
}
server {
    server_name urls.mapquest.com;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    location / {
        proxy_pass http://urls.mapquest.com;
    }
}

I want the nginx proxy to redirect to the application itself. I edited my hosts file on Ubuntu to point the new domain I specified. However, when I deploy the application locally, I get a 502 Bad Gateway error and looking in the logs for the Nginx container shows I am getting a Connection refused error:

nginx.1    | 2016/06/21 17:39:00 [error] 24#24: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: urls.mapquest.com, request: "GET / HTTP/1.1", upstream: "http://172.17.0.4:8081/", host: "site1.com"

Can anyone point me in the right direction of what the issue would be?

Upvotes: 3

Views: 6677

Answers (1)

GreenGodot
GreenGodot

Reputation: 6773

It turned out the application itself was having an issue. I was testing the docker-compose containers locally before making changes to the remote version and had forget to enable a certain configuration that was needed for my app to work.Once I had that corrected, the application loaded properly and nginx re-routed successfully.

Upvotes: 1

Related Questions