Https and the Host header

I am using Nginx as a proxy in front of a Java application (because it’s
hosted at Amazon where we only get one IP address per system, and I am
running multiple sites).

When the application calls getRequestURL, it gets http://dev.mysite.com
regardless of whether the request was actually http or https.

I am guessing that this is because Host gets set to either $host or
$http_host, both of which are dev.mysite.com, and somewhere along the
way an assumption gets made that that is http. I have tried setting
Host to https://dev.mysite.com but that returns a completely empty page

  • I assume that means it’s an invalid value for the Host header.

I have spent quite a bit of time researching this and I have found that
Django users experience a similar problem and the fix is to add a header
like X-Url-Scheme and pass along the value of $scheme, which will be
https at the appropriate times. However, I don’t see other Java users
reporting similar problems, and the fix seems kind of kludgy to me.

Does this mean I have something configured incorrectly, or is this just
the way it works? And if so is the above the best way to work around
it?

Thanks in advance!

Posted at Nginx Forum:

try this:

proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Server ssl;
proxy_set_header HTTPS 1;

and then let the app ask for one of these headers.

Posted at Nginx Forum: