symfonyvarnishliipimaginebundlefosjsroutingbundle

Symfony in nginx https + varnish + apache http = redirect loop or


I have configuration Symfony in nginx https + varnish + apache http = redirect loop

i put schemes for routing to get links https : ['https'] but get redirect loop why ? it look that symfony not just create links with https but return redirect if get http - i need http pages for cache in varnish but links https.

Update 1 When i put no schema in routing and run page over https almost everything work - without

1 fos routing it create absolute http links

2 liip imagine same situation


Solution

  • If you are getting a redirect to https despite using https when visiting the page, then the original protocol is not being forwarded to the backend that handles the response.

    There is a header X-Forwarded-Proto which should be set to contain the original protocol before it was passed through any proxies. Symfony should respect this header and accept that the request is secure and not redirect (and also set all links to https:// urls if appropriate)

    You need to configure Apache (which I assume is terminating the https connection and has the certificates) to set this header to match the original request protocol.

    It looks like you might need to trust the proxies before Symfony will obey the headers Symfony Docs for proxies

    // public/index.php
    
    // ...
    $request = Request::createFromGlobals();
    
    // tell Symfony about your reverse proxy
    Request::setTrustedProxies(
        // the IP address (or range) of your proxy
        ['192.0.0.1', '10.0.0.0/8'],
    
        // trust *all* "X-Forwarded-*" headers
        Request::HEADER_X_FORWARDED_ALL
    );