Skip to content

Commit 630f148

Browse files
authored
Merge pull request #889 from cakephp/ndm2-patch-1
Add switch to enable usage of `X-Forwarded-Proto`.
2 parents bf8f4cd + df807ef commit 630f148

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

config/bootstrap.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,18 @@
142142
*/
143143
$fullBaseUrl = Configure::read('App.fullBaseUrl');
144144
if (!$fullBaseUrl) {
145+
/*
146+
* When using proxies or load balancers, SSL/TLS connections might
147+
* get terminated before reaching the server. If you trust the proxy,
148+
* you can enable `$trustProxy` to rely on the `X-Forwarded-Proto`
149+
* header to determine whether to generate URLs using `https`.
150+
*
151+
* See also https://book.cakephp.org/4/en/controllers/request-response.html#trusting-proxy-headers
152+
*/
153+
$trustProxy = false;
154+
145155
$s = null;
146-
if (env('HTTPS')) {
156+
if (env('HTTPS') || ($trustProxy && env('HTTP_X_FORWARDED_PROTO') === 'https')) {
147157
$s = 's';
148158
}
149159

0 commit comments

Comments
 (0)