Jump to content

Need help configuring Prestashop with HTTPS/SSL (Rackspace/Load Balancer)


OllyL

Recommended Posts

[Edit: sorry this forum keeps losing half of what I type, have edited back in missing bits as best I can!]

 

Hi There,

 

We've got a Prestashop hosted on Rackspace with two front-end web servers sat behind a load balancer. The shop is here:

 

http://ratchetclothing.co.uk/

 

My clients want to use HTTPS / SSL for the checkout so we can have the padlock in the browser and to boost our customer's confidence in us, help secure sales etc.  I purchased an SSL Certificate and set this up on our load balancer and It's working correctly I think.

 

However when I go into admin to enable the SSL instead of the checkbox I get a link popping up which says:

 

"Please click here to enable SSL before continuing"

 

 

Even when viewing admin via https/ssl I could not remove the link but after some Googling I discovered one hack which got around it by adding some code to the top of config/settings.inc:

 

if( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ) {
    $_SERVER['SSL'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

 

This allows me to enable SSL in back office but once enabled my homepage gets stuck in a redirect loop permanently linking back to the HTTP site which kills the browser. I can fix the loop by switching on "Enable SSL on all pages" but once I do this I get other weird bugs appearing and the site doesn't seem 100% stable.

 

Has anyone managed to get Prestashop working with SSL on Rackspace or when behind a load balancer and if so could you help me out?

 

Thanks very much in advance,

 

Olly

Edited by OllyL (see edit history)
Link to comment
Share on other sites

Hi All,

 

I have managed to fix this. I was on the phone with our hosting company yesterday working on another issue and stumbled upon a solution. Basically the code block above is along the right lines but is not completely right. Putting this code block at the top of settings.php seems to work:

/* RACKSPACE SSL FIX */
if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&  ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'HTTPS' )) {
    $_SERVER['SSL'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}
else
{
	$_SERVER['SSL'] = 'off';
    $_SERVER['SERVER_PORT'] = 80;
}

The basic principal is that the load balancer receives HTTPS traffic on port 443 but then forwards it as regular HTTP traffic to the server on port 80. Obviously this port redirection plays havoc with Prestashop as all attempts it makes to redirect to port 443/Https keep coming back on port 80 and you get redirection loops occuring.

 

The code above simply picks up a header flag from the load balancer (X-Forwarded-Proto) and if enabled with switches on all the usual flags for SSL so Presta is tricked into thinking a regular HTTPS request has occured. I have tested on 1.6 and is working correctly

  • Like 4
Link to comment
Share on other sites

  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...