Skip to content

Commit 7ce3708

Browse files
authored
fix: redirect with real scheme from X-Forwarded-Proto (#484)
1 parent 962a645 commit 7ce3708

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

common/etc/nginx/templates/default.conf.template

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ map $request_uri $uri_full_path {
1313
"~^(?P<path>.*?)(\?.*)*$" $path;
1414
}
1515

16+
# Retrieves the initial scheme send by the User Agent. This uses
17+
# X-Forwarded-Proto header added by possible proxy or load balancer.
18+
map $http_x_forwarded_proto $real_scheme {
19+
default $http_x_forwarded_proto;
20+
"" $scheme;
21+
}
22+
1623
# Remove/replace a portion of request URL (if configured)
1724
map $uri_full_path $uri_path {
1825
"~^$STRIP_LEADING_DIRECTORY_PATH(.*)" $PREFIX_LEADING_DIRECTORY_PATH$1;
@@ -306,7 +313,7 @@ server {
306313
# 302 to request without slashes
307314
# Adding a ? to the end of the replacement param in `rewrite` prevents it from
308315
# appending the query string.
309-
rewrite ^ $scheme://$http_host$uri/$is_args$query_string? redirect;
316+
rewrite ^ $real_scheme://$http_host$uri/$is_args$query_string? redirect;
310317
}
311318

312319
# Provide a hint to the client on 405 errors of the acceptable request methods

0 commit comments

Comments
 (0)