Skip to content

Instantly share code, notes, and snippets.

@sathyanglg
Forked from jult/https_only
Created December 16, 2019 12:23
Show Gist options
  • Select an option

  • Save sathyanglg/98473fbf21799441831d1003fd90261b to your computer and use it in GitHub Desktop.

Select an option

Save sathyanglg/98473fbf21799441831d1003fd90261b to your computer and use it in GitHub Desktop.
[NGINX] Redirect all hostnames and requests from http to https serverwide
# To have port 80 requests go to their 443 equivalents for an entire webserver, put this file in /etc/nginx/conf.d/
# Note that to specify the catch-all name or default server you
# need to use the *listen* directive, not the server_name directive!
# See also https://nginx.org/en/docs/http/request_processing.html
#
# - $host catches subdomain names.
# - 307 and 308 include both POST and GET request URIs.
# - 307 is Temporary, change to the Permanent 308 after thorough testing: # return 308 https://$host$request_uri;
server {
listen 80 default;
listen [::]:80 default;
return 307 https://$host$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment