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 LiveForm which makes setting up contact forms on your website a breeze.