3

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?

2
  • Does your app work without nginx-proxy? And I don't understand why you have conf files for nginx-proxy. The point of nginx-proxy is that you don't (or rarely) need to configure the nginx-proxy other than linking it to your service. Commented Jun 21, 2016 at 19:00
  • I included the conf files just in case it was required. In any case, it turned out the application itself was having an issue. I was testing the containers locally before making changes to a remote instance and had forget a certain configuration was needed for my app to work. Commented Jun 23, 2016 at 9:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I am havin this exact issue, but my application logs do not show any malfunctioning, any idea?
I have this issue as well. Nothing wrong with my undockered application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.