Last active
February 9, 2017 13:35
-
-
Save jweyrich/7c94b8fe30eba8205981f2b359027bb4 to your computer and use it in GitHub Desktop.
Nginx - Redirect some traffic from HTTP to HTTPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set $needs_https_redir 1; | |
# Do not force HTTPS if the client is directly connecting to this server via | |
# HTTPS. | |
if ($scheme = 'https') { | |
set $needs_https_redir 0; | |
} | |
# Do not force HTTPS if the client is indireclty connecting to this server via | |
# HTTPS and the gateway tells us that through the X-Forwarded-Proto header. | |
if ($http_x_forwarded_proto = 'https') { | |
set $needs_https_redir 0; | |
} | |
# Do not force HTTPS if the client is requesting /foo/bar | |
if ($request_uri ~ ^/foo/bar$) { | |
set $needs_https_redir 0; | |
} | |
if ($needs_https_redir = 1) { | |
#rewrite ^ https://$host$uri permanent; | |
return 301 https://$host$uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment