Skip to content

Instantly share code, notes, and snippets.

@hilbix
Created February 3, 2020 12:40
Show Gist options
  • Save hilbix/b7246d4f1f27a116be7bd18f57752ef8 to your computer and use it in GitHub Desktop.
Save hilbix/b7246d4f1f27a116be7bd18f57752ef8 to your computer and use it in GitHub Desktop.
NginX HTTP -> HTTPS redirection with LetsEncrypt
server {
server_tokens off;
server_name _;
listen 80 default_server;
listen [::]:80 default_server;
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /etc/letsencrypt/web;
location / {
return 301 https://$host$request_uri;
}
location /.well-known/ {
try_files $uri @redirect;
}
location @redirect {
return 301 https://$host$request_uri;
}
}
@hilbix
Copy link
Author

hilbix commented Feb 3, 2020

  • default.conf replaces /etc/nginx/sites-available/default
  • LetsEncrypt challenges must go below /etc/letsencrypt/web/.well-known/

See also: https://github.com/hilbix/gen/blob/master/letsencrypt.http

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment