From: Bill Moseley
2010/3/25 Octavian Rasnita <
[email protected]>
The back end servers don't know if the current request is an http or an https one and on each redirect, > > they do the redirection using the http scheme.
(I have also set the configuration option using_frontend_proxy to true.)
> >
Also, because the back end servers receive only http requests, $c->req->secure is always equal to 0.
I have read that I can set the HTTPS environment variable to "On" and I put the following line in the
configuration file of the load balancer Apache server in the virtualhost that handles SSL requests:
> >
Does that header get to Catalyst? Obviously, check that first. >
I have this in a "after 'prepare_headers'": >
$res->secure( 1 ) if lc( $req->header( 'Https' ) || '' ) eq 'on'; >
The load balancer sends all traffic to the same port. The load balancer sets that header for SSL traffic.
I didn't know that HTTPS should be an HTTP header and not an environment variable so I have also added as a header.
I have put in the configuration file of the back end servers (to be sure that it will reach the app):
SetEnv HTTPS On
and in the configuration file of the load balancer server:
RequestHeader set HTTPS On
And in a test action I have done:
my $body;
$body .= "HTTPS environment variable: $ENV{HTTPS}<br />\n";
$body .= "HTTPS header: " . $c->req->header('HTTPS') . "<br />\n";
$body .= "secure: " . $c->req->secure . "<br />\n";;
$c->req->secure(1); #Force it to be true
$body .= "secure: " . $c->req->secure . "<br />\n"; # Check if it is set correctly
$body .= "uri_for_action: " . $c->uri_for_action('/user/login2') . "<br />\n";
$c->res->body($body);
And the result is:
HTTPS environment variable: On
HTTPS header: On
secure: 0
secure: 1
uri_for_action:
http://site.testsite.com:5555/en/user/login2So it seems that both the environment variable HTTPS and the header HTTPS are seen by Catalyst, but $c->req->secure is still equal to 0.
Do I need to add a certain plugin in order to be able to use $c->req->secure or what could be the problem that it is not set correctly?
I have read in Catalyst::Request:
"the URI scheme (eg., http vs. https) must be determined through heuristics; depending on your server configuration, it may be incorrect. See $req->secure for more info."
And more info:
"Note that the URI scheme (eg., http vs. https) must be determined through heuristics, and therefore the reliablity of $req->secure will depend on your server configuration. If you are serving secure pages on the standard SSL port (443) and/or setting the HTTPS environment variable, $req->secure should be valid."
I am accessing the site using SSL by the 5555 port so I need the HTTPS environment variable (or HTTP header) but I don't know why $c->req->secure is still not set.
And finally, even though I forced $c->req->secure to be true, $c->uri_for_action still uses the http scheme and not https so in the entire application the redirects won't be done correctly and this is the big problem.
Thanks.
Octavian