http to https rewrite, non-standard port?

John Moore grails at jmsd.co.uk
Mon Dec 6 14:47:10 MSK 2010


I want to rewrite all http requests for a host to https, on port 9443 
instead of the the standard 443. So I have this in my nginx.conf:

  server {
          server_name www.domain.com;
          listen 80;
          location / {
             rewrite  ^(.*)$ https://$host:9443$1 permanent;
          }
}

  server {
          server_name www.domain.com;
          listen 9443;
          location / {
             #etc...
          }
}


And as long as I use 'http://www.domain.com', the rewrite works fine. 
But some URLS are coming back now as 'http://www.domain.com:9443' and 
I'm running into the 400 error"The plain HTTP request was sent to HTTPS 
port", for obvious reasons. So how do I get it to rewrite 'http://' to 
'https://' as well, which is what I presume I need to do?



More information about the nginx mailing list