Force generation of HTTP / HTTPS link if behind caching server

Submitted by Berend Iwema - 10 years ago

For example, if you are using a caching server which listens on HTTPS, which retrieves your content from another (local server) which isn't using HTTPS, your links might be generated as http://mysite.com instead of the desired https://mysite.com. With this trick you can circumvent this.

//I've put the following in app/start/global.php:

// --- app/start/global.php --- //
// Set the trusted proxies so we can generate HTTPS routes - in my case, 127.0.0.1
\Symfony\Component\HttpFoundation\Request::setTrustedProxies(['127.0.0.1']);
// --- app/start/global.php --- //

/*
Now, ensure the caching server forwards the following header to the instance which serves your Laravel app:
X-Forwarded-Proto: https (or http if that is what you desire)

In case of an upstream in nginx, this would be:
proxy_set_header   X-Forwarded-Proto $scheme;
*/