First. install prerequisites:
apt install certbot python3-certbot-nginx
server_name example.com www.example.com;
certbot --nginx -d example.com -d www.example.com