I have one public IP address. I am trying to allow access via the public IP on ports 80 and 443 to multiple services, differentiated by requested server name.
HOWEVER, one service requires a TCP reverse proxy on ports 80 and 443 on the public IP to operate. Another requires TCP reverse proxy but just on port 443. The rest are just websites and fine with an http reverse proxy, but I want the websites publicly accessible on ports 80 and 443 to make it easy for visitors and for letsencrypt.
I can spin up as many VM's and private IP's as necessary to keep it simple, but limited to the one public IP address.
Can I do this with nginx setup as a reverse proxy using SNI? In theory I think I should be able to tcp stream everything by hostname using SNI directed to the appropriate server, with a second webserver that has the required websites setup to listen on different ports. For example, nginx.conf:
stream {
map $ssl_preread_server_name $name {
serviceone.domain.tld serviceone;
servicetwo.domain.tld servicetwo;
website1.domain.tld website1;
website2.domain.tld website2;
}
upstream serviceone {
server 10.1.99.7:443;
}
upstream servicetwo {
server 10.1.99.20:443;
}
upstream website1 {
server 10.1.99.30:10443;
}
upstream website2 {
server 10.1.99.30:10444;
}
server {
listen 443;
listen 80;
resolver 8.8.8.8;
proxy_pass $name;
ssl_preread on;
}
}
I have something working similar to the above in my nginx.conf, but am struggling a bit with understanding how port 80 requests come into the equation (I just slapped listen 80 in the server block, but could not explain how requests are handled in terms of differentiating between 443 and 80 if the same server name is requested)
I am open to better ways of doing it also using nginx or haproxy etc. Thanks!