0

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.

alexander.polomodov
  • 1,060
  • 3
  • 10
  • 14
Talon
  • 141
  • 4
  • This post contains two separate and distinct questions. The first one is answered [here](https://serverfault.com/q/562756/126632). 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 08 '18 at 03: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 08 '18 at 13:22

1 Answers1

4

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

...
location /mailhog/ {
   proxy_pass http://mailhog:8025/;
}
...
Talon
  • 141
  • 4