Skip to content

Commit b498de4

Browse files
committed
Update force_https.conf
1 parent 85cbfec commit b498de4

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
# Redirect all HTTP requests to HTTPS
1+
# Redirect to HTTPS if request is insecure:
2+
# - direct HTTP (nginx sees $scheme=http)
3+
# - and NOT already HTTPS on an upstream proxy (X-Forwarded-Proto != https)
24

3-
if ($scheme ~* ^(?!https).*$) {
4-
return 301 https://$host$request_uri;
5+
set $redirect_to_https 0;
6+
7+
if ($scheme != "https") {
8+
set $redirect_to_https 1;
9+
}
10+
11+
if ($http_x_forwarded_proto ~* '(^|,\s*)https($|,\s*)') {
12+
set $redirect_to_https 0;
513
}
14+
15+
if ($redirect_to_https) {
16+
return 301 https://$host$request_uri;
17+
}

0 commit comments

Comments
 (0)