I keep forgetting how to do exaclty the same thing: I often install things on a VPS and want a simple Nginx setup that proxies/forwards requests to that service’s port, as well as applies LetsEncrypt encryption. So here are all the steps.
Run these first to install Nginx and disable the default host:
sudo apt-get update
Then write a new file
/etc/nginx/sites-available/service, for example for a redirect on
/ on port 80 to port 8080:
And link it to enable it:
ln -s /etc/nginx/sites-available/service /etc/nginx/sites-enabled/service
At this point,
https://example.com/ should redirect to the service running on port 8080.
First install Certbot:
sudo apt-get install software-properties-common
Then run it for Nginx:
sudo certbot --nginx
Be sure to pick your domain for automatic host file update, and choose whether to redirect HTTP to HTTPS (HSTS).
The new host file should like the following after being rewritten by Certbot:
The same thing can be accomplished using Docker with the nginx-le image. You just have to write the nginx config files and mount them using the