Lets encrypt auto renewal for ubuntu and nginx

Create a file called /etc/nginx/le_redirect_include.conf

1
2
3
4
5
6
7
8
9
10
# intercept the challenges
location '/.well-known/acme-challenge' {
default_type "text/plain";
root /usr/share/nginx/letsencrypt;
}
# redirect all traffic to the https version
location / {
return 301 https://$host$request_uri;
}

In your redirect block include this file

1
2
3
4
server {
server_name www.liveformhq.com liveformhq.com;
include /etc/nginx/le_redirect_include.conf;
}

To generate the LE keys run the following

1
2
3
4
5
sudo mkdir -p /usr/share/nginx/letsencrypt
# generate the certificate
sudo letsencrypt certonly --webroot=/usr/share/nginx/letsencrypt --domain cosmicvent.com --domain www.cosmicvent.com
# reload nginx
sudo kill -s HUP $(cat /var/run/nginx.pid)

Put the following in your crontab

1
2
$ sudo crontab -e
@weekly /usr/bin/letsencrypt &> /tmp/letsencrypt.log; sudo kill -s HUP $(cat /var/run/nginx.pid)


I am currently working on Zammu which makes Automatic Deployment of static websites to Github Pages very easy. I would love to get your feedback on it, Use the invitation code KHAJA