Secure Nginx with Let's Encrypt on Ubuntu 18.04 with DNS Validation

Originally published at: https://www.cyberciti.biz/faq/secure-nginx-with-lets-encrypt-on-ubuntu-18-04-with-dns-validation/

How do I install and secure Nginx with Let’s Encrypt on Ubuntu 18.04 with DNS validation API? My domain DNS hosted with Cloudflare. How do I install Let’s Encrypt to create SSL certificates with Nginx web server running on an Ubuntu Linux 18.04 LTS server?