Add HTTPS to an Nginx website hosted on Digital Ocean
SSH into server as sudo user
You need to be logged in as a sudo user since some of the subsequent commands require sudo privileges.
Install snapd
Install snapd if you haven’t already. Ubuntu 18.04 and up should already have it installed.
Ensure your snapd version is up to date
sudo snap install core; sudo snap refresh core
Remove any Certbot OS packages
Let’s remove any existing Certbot command.
sudo apt-get remove certbot
Install Certbot snap
sudo snap install --classic certbot
Prepare Certbot command
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Install certificates
Run the following command to acquire and install certificates for example.com
and *.example.com
(replace with your own domain):
sudo certbot --nginx -d example.sajadtorkamani.com -d www.example.sajadtorkamani.com
This command does a few things:
- Installs the SSL certificates at
/etc/letsencrypt/live
- Configures your Nginx
config
to listen on the SSL port 443 - Configures your Nginx config to redirect all HTTP requests to HTTPS
You can also choose to only generate the certificates and manually modify your Nginx configs by running sudo certbot certonly
followed by the same arguments and flags as above.
The certbot tool is pretty clever so it will interactively prompt you for actions/confirmations when it detects any existing configuration that may be problematic.
Sources
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment