Skip to content

Instantly share code, notes, and snippets.

@mudge
Last active February 6, 2017 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mudge/7dffb18b4746a291109ba756584dcb8e to your computer and use it in GitHub Desktop.
Save mudge/7dffb18b4746a291109ba756584dcb8e to your computer and use it in GitHub Desktop.
Handling Fastly TLS termination in nginx with map: http://nginx.org/en/docs/http/ngx_http_map_module.html
# Declares a new variable, $forwarded_scheme, that contains the URL scheme
# used by a user even if Fastly terminates your TLS connections.
#
# Will use the scheme extracted from the request URI by default or return
# "https" if the Fastly-SSL HTTP header is found.
map $http_fastly_ssl $forwarded_scheme {
default $scheme;
"1" "https";
}
# And then elsewhere...
server {
server_name example.com;
return 301 $forwarded_scheme://www.example.com$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment