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.

2
  • 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. Commented Nov 8, 2018 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. Commented Nov 8, 2018 at 13:22

1 Answer 1

4

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

... location /mailhog/ { proxy_pass http://mailhog:8025/; } ... 
1
  • Man!! Seriously.. Didn't imagine I wasted hours on this!.. Thanks, Worked for me Commented Jul 2, 2020 at 15:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.