EDIT: After the comments, more reading and several rounds with good colleagues we've come to the conclusion that as long as we do not have control over the back-end server, the usage of custom SSL ports will be impossible since we cannot instruct the back-end to facilitate it. I'll leave the question here, still, since it may help others in the future to reach the same conclusion and not waste hours of research. And the slight chance that someone may prove us wrong.
We have a chat server where customers can connect directly to our CS representatives. We have several web sites on different domains where an iframe chat box is served from and thus because off the cross-site scripting issue, we need to serve several different SSL certs on the reverse proxy. To solve this without setting up one NGINX reverse proxy per domain (there are many), we would like to serve all domains on custom ports on one NGINX, so it would look like this:
chat.domainA.com:443 -> chat_server:80
chat.domainB.com:2001 -> chat_server:80
chat.domainC.com:2002 -> chat_server:80
This is how I have tried to set then NGINX reverse proxy up:
server {
listen 443 ssl;
server_name chat.domainA.com;
access_log /var/log/nginx/ssl-access.log;
error_log /var/log/nginx/ssl-error.log;
ssl_certificate /etc/nginx/ssl/chat.domainAbundle.com.crt.pem; # Cert chain
ssl_certificate_key /etc/nginx/ssl/chat.domainA.com.key.pem;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
[...]
SSL Specific information, ciphers, etc
[...]
location / {
proxy_pass http://internal_chat_server/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 2001 ssl;
server_name chat.domainB.com;
access_log /var/log/nginx/ssl-access.log;
error_log /var/log/nginx/ssl-error.log;
ssl_certificate /etc/nginx/ssl/chat.domainBbundle.com.crt.pem; # Cert chain
ssl_certificate_key /etc/nginx/ssl/chat.domainB.com.key.pem;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
[...]
SSL Specific information, ciphers, etc
[...]
location / {
proxy_pass http://internal_chat_server/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 2002 ssl;
server_name chat.domainC.com;
access_log /var/log/nginx/ssl-access.log;
error_log /var/log/nginx/ssl-error.log;
ssl_certificate /etc/nginx/ssl/chat.domainCbundle.com.crt.pem; # Cert chain
ssl_certificate_key /etc/nginx/ssl/chat.domainC.com.key.pem;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
[...]
SSL Specific information, ciphers, etc
[...]
location / {
proxy_pass http://internal_chat_server/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
The issue we are having is that if we access for instance https://chat.domainB.com:2001 then we get redirected back to https://chat.domainB.com (on port 443) where obviously we get a certificate error, since it is chat.domainA.com's certificate listening to that port. Connections to https://chat.domainA.com works fine.
We have tried several solutions to force the reverse proxy server to keep the port number, but no matter what we have tried it still reverts to port 443.
We've played with rewrites and sub-folders, redirects (which causes a loop), proxy_set_header Host $host:$server_port, etc. but nothing helps. Please do not regard the above config as our only attempt, this was just the "cleaner" code.
The internal chat server is a Cisco appliance which we cannot do any configuration on ourselves, so any configuration needs to be done on the reverse proxy. Do we really have to set up a reverse proxy per domain, or is there something we've overlooked?
Any help is highly appreciated.