This is how I configured my reverse proxy using nginx. There are docker container with nodeJS applications running (app1, app2, ...)
With this I point via localhost:8080 to the docker container app1 nodeJS application and with localhost:8081 to app2.
But I want to call the apps via subdomains without using the ports and I don't see how do get this. I also think I messed up the ports...
app1.localhost should point to app1 and app2.localhost should point to app2.
nginx.conf
http {
sendfile on;
upstream docker-app1 {
server app1:80;
}
upstream docker-app2 {
server app2:80;
}
server {
listen 8080;
server_name app1.localhost;
location / {
proxy_pass http://docker-app1;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
#proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
}
}
server {
listen 8081;
server_name app2.localhost;
location / {
proxy_pass http://docker-app2;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
#proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
}
}
}
docker-compose.yml
version: '3.3'
services:
nginx:
container_name: 'nginx'
image: 'nginx:1.13.5'
restart: 'always'
ports:
- '80:80'
- '8080:8080'
- '8081:8081'
- '443:443'
volumes:
- './nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro'
app1:
container_name: app1
build: ./app1
restart: always
ports:
- '3001:80'
app2:
container_name: app2
build: ./app1
restart: always
ports:
- '4200:80'
Update: As Sergiu provided a good link for reverse proxy, I updated the post with the new configuration; the question is still the same