$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt install python-certbot-nginx
$ sudo nano /etc/nginx/sites-available/example.com
change server_name
...
server_name example.com www.example.com;
...
$ sudo nginx -t
$ sudo systemctl reload nginx
$ sudo ufw status
$ sudo ufw allow 'Nginx Full'
$ sudo ufw delete allow 'Nginx HTTP'
$ sudo ufw status
should like this :
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
$ sudo certbot --nginx -d example.com -d www.example.com
$ sudo certbot renew --dry-run