1

I'm trying to get Nginx to reverse proxy connections within a lan to several web applications including ones inside docker containers.

Both webapps are reachable with the proxy_pass url

I'm using the following dockerfile:

# Set the base image to Ubuntu
FROM ubuntu

RUN apt-get update
RUN apt-get install -y nginx

RUN rm -v /etc/nginx/nginx.conf
RUN echo "daemon off; \n\
 \n\
worker_processes 1; \n\
events { worker_connections 1024; } \n\
 \n\
http { \n\
 \n\
    server { \n\
        listen 99; \n\
 \n\
        server_name dashboard; \n\
        location / { \n\
            proxy_pass http://dashboard:80; \n\
        } \n\
        location /app1 { \n\
            proxy_pass http://otherhostname:9000/app1; \n\
        } \n\
    } \n\
} \n\

" >> /etc/nginx/nginx.conf
EXPOSE 99
CMD service nginx start

When running this as a service (container) I can reach app1, but not the dashboard.

The weird thing is that I had this working before, and I'm pretty sure I did not change anything fundamental to the dockerfile. Am I missing something?

EDIT: (I have currently exposed the dashboard on port 80, and am testing on 99 with nginx)

I run the nginx container with:

docker service create \
    --replicas 1 \
    --name nginx \
    -p 99:99 \
    nginx_image

the dashboard also has the correct port exposed.

docker service create \
    --replicas 1 \
    --name dashboard \
    -p 80:8080 \
    dashboard_image

Looking in the nginx error.log I found:

2016/11/08 08:46:41 [error] 25#25: *42 upstream timed out (110: Connection timed out) while connecting to upstream, client: 10.255.0.3, server: dashboard, request: "GET / HTTP/1.1", upstream: "http://dockerhostip:80/", host: "dashboard:99"
p.streef
  • 3,652
  • 3
  • 26
  • 50
  • Please share also information about how you setup the `nginx` and `dashboard` containers (e.g. `docker-compose.yml` file). – ronkot Nov 08 '16 at 08:45
  • In case it might help I wanted to do pretty much the same thing: http://stackoverflow.com/questions/32195108/docker-run-apache-on-host-and-container-for-different-websites/32209615#32209615 It's not a duplicate but it's related I'd say. – AntoineB Nov 08 '16 at 08:57
  • thanks guys, I found the problem is actually not in nginx at all, but in the dashboard. Which is weird because it ~used to work just fine~. Back to investigating! – p.streef Nov 08 '16 at 09:05

1 Answers1

1

Nginx is working as intended. I found when changing the proxy pass to example.com it works fine. It must be something that changed in the dashboard that messes things up.

p.streef
  • 3,652
  • 3
  • 26
  • 50