STEP1. System Requirements #
- Ubuntu 24.04
- Docker, Docker Compose
- Domain (example: test.bestnetllc.co.jp)
- Let’s Encrypt SSL certificate
STEP2. OS and Docker Installation #
Update OS #
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get autoremove -y
sudo apt-get autoclean
sudo reboot
Install Docker and Docker Compose #
sudo apt-get update
sudo apt-get install -y
ca-certificates
curl
gnupg
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg
| sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg]
$(lsb_release -cs) stable"
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
docker --version
docker compose version
STEP3. Initial SSL Certificate Issuance #
Create certificate storage directory #
sudo mkdir -p /opt/certs/letsencrypt
Stop Nginx temporarily and issue certificate #
sudo docker run -it --rm
-p 80:80
-v /opt/certs/letsencrypt:/etc/letsencrypt
certbot/certbot certonly --standalone
-d test.bestnetllc.co.jp
-m test@bestnetllc.co.jp
--agree-tos
--no-eff-email
Verify success:
ls /opt/certs/letsencrypt/live/test.bestnetllc.co.jp
STEP4. Dify Installation and Configuration #
Clone repository #
cd /home
mkdir dify && cd dify
git clone https://github.com/langgenius/dify.git
cd dify/docker
Configure .env #
nano .env
Environment variable example:
CERTBOT_EMAIL=test@bestnetllc.co.jp
CERTBOT_DOMAIN=test.bestnetllc.co.jp
NGINX_HTTPS_ENABLED=true
NGINX_SSL_PROTOCOLS="TLSv1.2 TLSv1.3"
NGINX_SSL_CERT_FILENAME=live/test.bestnetllc.co.jp/fullchain.pem
NGINX_SSL_CERT_KEY_FILENAME=live/test.bestnetllc.co.jp/privkey.pem
Nginx configuration example in docker-compose.yaml #
services:
nginx:
image: nginx:latest
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- type: bind
source: /opt/certs/letsencrypt
target: /etc/letsencrypt
read_only: true
- ./nginx/nginx.conf.template:/etc/nginx/nginx.conf.template
- ./nginx/conf.d:/etc/nginx/conf.d
environment:
NGINX_HTTPS_ENABLED: "true"
NGINX_SSL_CERT_FILENAME: "live/test.bestnetllc.co.jp/fullchain.pem"
NGINX_SSL_CERT_KEY_FILENAME: "live/test.bestnetllc.co.jp/privkey.pem"
NGINX_SSL_PROTOCOLS: "TLSv1.2 TLSv1.3"
Start and verify operation #
docker compose up -d
docker compose logs -f nginx
Access https://test.bestnetllc.co.jp in your browser
STEP5. Automatic SSL Certificate Renewal Setup #
Create renewal script #
sudo nano /opt/certs/renew_cert.sh
Script contents:
#!/bin/bash
cd /home/dify/docker
docker compose stop nginx
docker run --rm
-p 80:80
-v /opt/certs/letsencrypt:/etc/letsencrypt
certbot/certbot renew --standalone
docker compose start nginx
sudo chmod +x /opt/certs/renew_cert.sh
Configure cron job #
sudo crontab -e
Add the following (every Sunday at 3:00 AM):
0 3 * * 0 /opt/certs/renew_cert.sh >> /var/log/letsencrypt_renew.log 2>&1
Test operation #
sudo /opt/certs/renew_cert.sh
STEP6. Troubleshooting #
When issues occur, check the logs:
docker compose logs api -f
docker compose logs worker -f
docker compose logs web -f
docker compose logs nginx -f
Internal Server