Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @neilstuartcraig neilstuartcraig created this gist Apr 4, 2014.
    21 changes: 21 additions & 0 deletions Nginx http to https redirect
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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;
    }