Skip to content

Instantly share code, notes, and snippets.

@lman
Forked from donpdonp/example.com.conf
Created December 14, 2022 20:49
Show Gist options
  • Save lman/70ee78da3ae1c2461c0429bf847dd08b to your computer and use it in GitHub Desktop.
Save lman/70ee78da3ae1c2461c0429bf847dd08b to your computer and use it in GitHub Desktop.
nginx.conf https only with letsencrypt using lego client
# /etc/nginx/sites-enabled/example.com.conf
server {
listen 80;
server_name .example.com;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name .example.com;
ssl_certificate /var/letsencrypt/certificates/example.com.crt;
ssl_certificate_key /var/letsencrypt/certificates/example.com.key;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://internal-content-host;
}
}
# one time setup
$ go get -u github.com/xenolf/lego
$ lego --email letsencrypt@example.com --domains example.com --path /var/letsencrypt --webroot /var/letsencrypt/webcache run
# renew (can be run from cron)
$ lego --email letsencrypt@example.com --domains example.com --path /var/letsencrypt --webroot /var/letsencrypt/webcache renew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment