We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 85cbfec commit b498de4Copy full SHA for b498de4
1 file changed
resources/modules/Nginx/conf/snippets/force_https.conf
@@ -1,5 +1,17 @@
1
-# Redirect all HTTP requests to HTTPS
+# 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)
4
-if ($scheme ~* ^(?!https).*$) {
- 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;
13
}
14
15
+if ($redirect_to_https) {
16
+ return 301 https://$host$request_uri;
17
0 commit comments