This guide provides instructions for setting up an SSL certificate on an Ubuntu Server using Docker, Nginx, and Certbot.
- Docker and Docker Compose installed
- Ubuntu Server with sudo privileges
- Domain name pointing to your server's IP address
docker compose build
sudo apt-get update
sudo apt-get upgrade
mkdir -p certificates
mkdir -p certificates/bot
Generate a temporary self-signed certificate to ensure Nginx runs initially.
cd certificates
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout privkey.pem -out fullchain.pem
cd ..
Place your default.conf
and docker-compose.yaml
in the project's root directory.
docker compose up -d
sudo apt install certbot
Replace [PATH]
with your certificates directory path and [DOMAIN_NAME]
with your domain name.
sudo certbot certonly --webroot -w [PATH]/certificates/bot -d [DOMAIN_NAME]
Example:
sudo certbot certonly --webroot -w /home/ubuntu/search-engine-shopee/nginx/certificates/bot -d search.vectornguyen.com
Copy the Let's Encrypt certificates to your certificates directory.
sudo cp /etc/letsencrypt/archive/[DOMAIN_NAME]/fullchain1.pem [PATH]/certificates/fullchain.pem
sudo cp /etc/letsencrypt/archive/[DOMAIN_NAME]/privkey1.pem [PATH]/certificates/privkey.pem
Example:
sudo cp /etc/letsencrypt/archive/search.vectornguyen.com/fullchain1.pem /home/ubuntu/search-engine-shopee/nginx/certificates/fullchain.pem
sudo cp /etc/letsencrypt/archive/search.vectornguyen.com/privkey1.pem /home/ubuntu/search-engine-shopee/nginx/certificates/privkey.pem
docker compose restart
Regularly renew certificates close to expiration.
sudo certbot renew
- Ensure your domain name is correctly configured to point to your server's IP.
- Regularly check for certificate expiration and renew as needed.