Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let Symfony 2 adopt the protocol scheme (http vs https)

I have a Symfony 2 website that either runs on HTTP in development or on HTTPS in production.

I noticed that in production the URL's generated by Symfony are still all rendered as HTTP.

How can I either;

  1. Let the framework adopt the current protocol from which the website is served (probably preferred)?
  2. Or, force the entire website in HTTPS mode only in production?
like image 490
Luke Avatar asked Feb 05 '15 20:02

Luke


1 Answers

Assuming this case :

  • Your Symfony app is behind a reverse proxy like Varnish or BigIP
  • You want to use original client IP as REMOTE_ADDR (i.e with mod_rpaf apache extension) (of course in this case you can't use trusted_proxies value)

You can set HTTPS environment variable in your webserver, indexed on X-FORWARDED-PROTO header value, to force Symfony to use https protocol.

In Apache :

SetEnvIf x-forwarded-proto https HTTPS=on
like image 85
dryobs Avatar answered Sep 17 '22 20:09

dryobs