I have two local web apps which should be accessible from external network, but only one external IP. Both web apps use 443 port which can't be changed. So the task is to configure nginx in the way so that it can forward the incoming requests based on the 3rd level domain.
Let's say my web apps live on 192.168.1.55 and 192.168.1.65
My public IP is 9*.23*.15*.12 and I have configured 2 dns A entries site1.example.com and site2.example.com which are both mapped to my public IP.
In my ideal world I want nginx to forward all incoming requests with $server_name = site1.example.com to 192.168.1.55 and with $server_name = site2.example.com to 192.168.1.65
Please advise how it can be achieved.
At the moment I was able to configure only simple forwarding to one of the web apps.
server {
listen 443 ssl http2;
server_name site1.example.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/blog.zeroxzed.ru/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.zeroxzed.ru/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
location /.well-known/acme-challenge/ {
root /web/sites/example.com/www/;
}
location / {
proxy_pass https://192.168.1.55;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}