I have a network of 3 containers set up in a docker-compose.yml. 2 containers are web applications and the third is a reverse proxy. All 3 containers run nginx. This is the nginx.conf for the reverse proxy:
events {}
http {
server {
listen 8090;
server_name localhost;
location / {
proxy_pass http://myappui:8080;
}
location /admin/ {
proxy_pass http://myappadmin:8081/;
# this works proxy_pass http://microsoft.com/;
}
}
}
The problem is that the proxy_pass for the location /admin/ somehow routes calls to the first container as http://myappui:8080/admin rather than passing to the second container as http://myappadmin:8081/. If, for location /admin/, I replace myappadmin:8081 with microsoft.com, it works and the calls are correctly routed to microsoft.com.
If I call the second container myappadmin with the automatically assigned host port, it opens the myappadmin application correcly.
This is my docker-compose:
version: '3.4'
services:
myappui:
build:
dockerfile: ./Docker/Dockerfile.ui
tty: true
container_name: myappui
ports:
- "8080"
networks:
- webnet
myappadmin:
build:
dockerfile: ./Docker/Dockerfile.admin
tty: true
container_name: myappadmin
ports:
- "8081"
networks:
- webnet
nginx:
image: nginx:latest
tty: true
container_name: myappreverseproxy
ports:
- "8090:8090"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
networks:
- webnet
networks:
webnet :
driver: bridge