Hoping for some guidance. I’ve Googled but seem to be in no luck. I’ve found the following, but these don’t appear to be the same issue:
I have a VPS with two external IP addresses, and a domain address pointed to each:
- domain1 : 212.x.x.149
- domain2 : 89.x.x.60
I have Docker on this VPS and Nginx running within it.
I want to specify Nginx to render the correct website depending on the domain that the user arrived from.
In order to do this (and it doesn’t work so I’m either completely off track or missing a piece), I have done the following:
docker-compose.yml
version: "3"
services:
nginx:
image: nginx:latest
container_name: nginx
volumes:
- ~/nginx/conf:/etc/nginx/conf.d
networks:
- domain1net
- domain2net
ports
- "80:80"
- "443:443"
networks:
domain1net:
external: true
domain2net:
external: true
My domain1 network is 172.18.0.0/16, and domain2 is 172.19.0.0/16.
This said, I’m unsure that these are actually mapped to the external IP’s?
Nginx default.conf
server {
listen 172.18.0.2:80;
server_name: domain1;
location / {
root ...
}
}
server {
listen 172.19.0.5:80;
server_name: domain2;
location / {
proxy_pass http...
}
}
Right now, whichever external IP address I go to, I’m seeing the first website (which right now is just the default ‘welcome to nginx!’ page.
Can someone help me understand how to map the two external IP addresses?
Regards,
Andy
2
Answers
I fixed it.
Needed to set the listen to simply '80' and then the server_name needed to be the IP address rather than the domain name.
glad that you fixed it, although will be good to have a better look at this post about creating a multiple website server with docker-compose nginx and letsencrypt.