9
votes

What is a clean, Symfony way of ensuring HTTPS is being used in Symfony2 when behind an EC2 load balancer that is handling the SSL connection and sending it to you as HTTP.

If you do something like requires_channel you get a redirect loop after the initial change to HTTPS because on the webserver itself you are still doing HTTP. The url does show HTTPS though, and Amazon provide a X-FORWARDED-PROTO header to use as well.

Is there a clean way of having symfony2 handle this kind of situation?

2

2 Answers

7
votes

You should check if this method is suitable for you.

In your app.php before the $kernel->handle(...); you should set:

Request::trustProxyData();

UPDATE:

You can also configure your application in config.yml (see doc):

framework:
    ...
    trust-proxy-headers: true
0
votes

The trusted_proxies option was removed in Symfony 3.3. See How to Configure Symfony to Work behind a Load Balancer or a Reverse Proxy.