Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
SSL redirect issues using AWS ELB
  • Finally my project is ready for staging. The server setup is basically:

    2 AWS EC2 instances
    1 AWS Elastic Load Balancer to divy up the load

    I've setup my SSL certificate on the ELB. However, internally, the ELB uses unsecured HTTP (port 80) to request data from each of the EC2 instances and return it to the browser. As a result, \Input::protocol() is "http" and whenever I do a \Response::redirect('wherever'), FuelPHP will redirect to the http:// location, rather than using https. After doing a bit of research I found that the ELB sets the 'HTTP_X_FORWARDED_PROTO' server variable to 'https' in this case.

    For the moment I've resolved the issue by setting my 'base_url' parameter in my config file. However, this isn't ideal because I have development, testing, staging and production environments on different subdomains, and I don't really want to maintain a different config file for each one. Is there any way to honor the HTTP_X_FORWARDED_PROTO server variable?
  • HarroHarro
    Accepted Answer
    I have something similar, all our internet facing webservers are behind reverse proxies. These will inject

    RequestHeader add X-Frontend-HTTPS on

    in the virtual host definition that proxies the request. On the frontend server itself, I capture this additional header in the request using

    # fake HTTPS if we had an SSL connection
    <IfModule env_module>
        SetEnvIf X-Frontend-HTTPS "^on$" HTTPS=on
    </IfModule>

    Which creates $_SERVER['HTTPS'] = 'on' on the PHP side, causing URI's to be generated with a https scheme.

    You can do the same with HTTP_X_FORWARDED_PROTO.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion