0

This question already has an answer here:

I am attempting to set a reverse proxy using the nginx container with a few other containerized app being routed too behind. I have modified the default.config in nginx to below. I have not changed anything in nginx.config.

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    location /mailhog {
        proxy_pass http://mailhog:8025;
    }

    location /httpd {
        proxy_pass http://httpd:8080;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

My dockerfile uses the nginx image and just replaces the default.config.

Docker run command

docker run -d --name mailhog -p 8025:8025 mailhog/mailhog
docker run -d --name httpd -p 8080:80 httpd    
docker run -d --name mynginx --link=httpd --link=mailhog -p 80:80 mynginx

When I navigate to / I get the standard nginx index page. Mailhog give a 404 and httpd give a 502. I have tried a couple variations of the docker runs command such as using --expose or not opening any ports. If I navigate the actual url, the apps work fine, just not through the reverse proxy.

I got this strategy from here. I have looked at using nginx-proxy but I don't want to use subdomain.domain url pattern.

marked as duplicate by Michael Hampton nginx Nov 8 '18 at 14:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • This post contains two separate and distinct questions. The first one is answered here. For the other one, your httpd container probably didn't start correctly. You need to check your logs. And you probably should be using docker-compose. – Michael Hampton Nov 8 '18 at 3:45
  • Thanks for the link. Solved the problem. I plan on using docker compose but I wanted to get my reverse-proxy container working first. – Talon Nov 8 '18 at 13:22
1

The problem was the proxy_pass url requires a slash at the end.

...
location /mailhog/ {
   proxy_pass http://mailhog:8025/;
}
...

Not the answer you're looking for? Browse other questions tagged or ask your own question.