Created
April 4, 2014 11:37
-
-
Save neilstuartcraig/9972763 to your computer and use it in GitHub Desktop.
Nginx http to https redirect (maintaining hostname, path and query string - using an HTTP 301)
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
server { | |
# Listen on port 80 for any IPv4 address on this server | |
# listen docs: http://wiki.nginx.org/HttpCoreModule#listen | |
listen 80; | |
# Listen on only the selected hostname... | |
server_name <HOSTNAME>; | |
# ...or use the catchall character if you want to handle multiple hostnames | |
# server_name _; | |
# Turn off logging for the redirect. Enable this the usual way if you need it: | |
# Access log docss: http://wiki.nginx.org/HttpLogModule | |
access_log off; | |
# Error log docs: http://wiki.nginx.org/CoreModule#error_log | |
error_log off; | |
# Rewrite (redirect) the request to https... | |
# maintaining the hostname ($server_name), path ($request_uri) and query string ($query_string)... | |
# via an HTTP 301 (permanent) | |
rewrite ^ https://$server_name$request_uri?$query_string permanent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this gist is incorrect: the
$request_uri
includes the$query_string
(aka arguments), see Nginx Docs.If you want a something without the
$query_string
, you have to create it yourself.