Docker Part Two: Provision a VPS with Nginx and SSL
Now that we've got a Docker image built and pushed to Docker Hub, we need somewhere to run it. Let's provision a fresh server, install Nginx, and get HTTPS sorted.
I'll assume you've got a domain name and a VPS provider of your choice (DigitalOcean, Hetzner, Scaleway, whatever takes your fancy).
Step 1: SSH into your machine
Your provider will give you an IP address and credentials. SSH in.
Step 2: Update everything
apt update && apt upgrade -yStep 3: Install Nginx
apt install nginx -yStep 4: Create a test site
If you're planning to host multiple domains on one box, create subdirectories:
mkdir -p /var/www/example.com/html
nano /var/www/example.com/html/index.htmlChuck in some basic HTML:
<html>
<head>
<title>Welcome to example.com</title>
</head>
<body>
<h1>Hello World!</h1>
<p>You have accessed the example.com website.</p>
</body>
</html>Step 5: Configure Nginx
nano /etc/nginx/sites-available/example.comAdd your server block:
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}Edit root and server_name to match your actual domain.
Step 6: Enable the site
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/Step 7: Verify and restart
nginx -t
systemctl restart nginxYou should now see your site over HTTP.
Step 8: Install SSL with Certbot
Certbot handles Let's Encrypt certificates automatically. Install it via snap (the modern way):
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbotRun the wizard:
sudo certbot --nginx -d example.com -d www.example.comIt'll modify your Nginx config to handle HTTPS and set up auto-renewal. Done.
Previous: Docker Part One: Create an Image. Next: Deploy a Container to the Web
