Friday, May 30, 2008

HTTPS with Mongrel and Apache

Recently I was trying to configure my Railsmachine server for conditional http access. I was using something similar to ssl_requirement.

In this plugin there is the following call


request.ssl?


Of course behind apache this is returning false, even when the browser is using https. This happens because of mod_proxy.

The solution is to set the X_FORWARDED_PROTO 'https' env=HTTPS

HTTPS is an environment variable set in Apache (which versions I don't know)

X_FORWARDED_PROTO makes rails understand the original protocol and request.ssl? returns true where appropriate.

In short, add the following to your httpd.conf




RequestHeader set X_FORWARDED_PROTO 'https' env=HTTPS

No comments: