Install certbot
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
sudo certbot --authenticator standalone --installer nginx -d www.example.com --pre-hook "service nginx stop;sleep 5;" --post-hook "service nginx start;sleep 5;"
Auto renew cronjob
#cronjob renew cert
0 23 * * 6 certbot renew --pre-hook "service nginx stop;sleep 10;" --post-hook "service nginx start;"