
클라우드 플레어 활용하기 🚀
웹사이트 성능과 보안을 한 단계 업그레이드! 👨💻
안녕하세요! 오늘은 웹사이트 운영에 필수적인 클라우드 플레어(Cloudflare)를 활용하는 방법에 대해 상세히 알아보겠습니다. 도메인 연결부터 DDNS 설정, 그리고 SSL 인증서 관리까지 모든 과정을 단계별로 설명해 드릴게요. 🌐
1️⃣ 클라우드 플레어에 도메인 연결하기 🔗
클라우드 플레어는 무료로 제공되는 CDN 서비스이자 DNS 관리 도구로, 웹사이트의 속도와 보안을 크게 향상시킬 수 있습니다. 이제 도메인을 연결하는 방법을 알아보겠습니다.
📝 단계별 가이드
1단계: 계정 생성 및 로그인 📲
- Cloudflare 웹사이트에 접속합니다.
- “Sign Up” 버튼을 클릭하여 계정을 생성하거나, 기존 계정으로 로그인합니다.
2단계: 도메인 추가 ➕
- 대시보드에서 “Add a Site” 또는 “사이트 추가” 버튼을 클릭합니다.
- 연결하려는 도메인(예:
example.com
)을 입력하고 “Add Site”를 클릭합니다.
💡 TIP: 서브도메인이 아닌 루트 도메인을 입력해야 합니다.
예) O: example.com | X: blog.example.com
3단계: 플랜 선택 💰
- 무료 플랜이나 다른 유료 플랜 중에서 선택합니다.
- 대부분의 개인 사이트는 무료 플랜으로도 충분합니다.
- “Continue” 버튼을 클릭합니다.
4단계: DNS 레코드 확인 ✅
- Cloudflare가 자동으로 기존 DNS 레코드를 스캔합니다.
- 모든 레코드가 제대로 가져와졌는지 확인합니다.
- 예) A 레코드, CNAME 레코드, MX 레코드 등
실제 예시:
Type Name Content TTL Proxy status
A @ 203.0.113.50 Auto Proxied
CNAME www example.com Auto Proxied
MX @ mail.example.com Auto DNS only
TXT @ v=spf1 -all Auto DNS only
필요한 경우 레코드를 추가하거나 수정합니다:
- 블로그를 호스팅하는 서버가 있다면 A 레코드 추가:
blog 203.0.113.51 Auto Proxied
- 이메일 서버를 위한 MX 레코드:
@ 10 mail.example.com Auto DNS only
5단계: 네임서버 변경 🔄
Cloudflare가 제공하는 네임서버 정보를 기록해둡니다.
예시:
ns1.cloudflare.com ns2.cloudflare.com
도메인 등록 기관(예: GoDaddy, Namecheap, 가비아 등)의 관리 패널에 로그인합니다.
네임서버 설정 메뉴로 이동합니다.
기존 네임서버를 Cloudflare에서 제공한 네임서버로 변경합니다.
예시 (가비아의 경우):
- 가비아 로그인 → 도메인 관리 → 네임서버 설정
- “네임서버 직접 설정” 선택
- 클라우드플레어 네임서버 입력:
ns1.cloudflare.comns2.cloudflare.com
- 저장
6단계: 네임서버 변경 확인 및 활성화 🟢
- 네임서버 변경이 적용되는 데는 최대 24시간이 소요될 수 있습니다. (보통 몇 시간 내로 적용됨)
- Cloudflare 대시보드에서 상태를 확인합니다.
- “Status: Active” 메시지가 표시되면 성공적으로 연결된 것입니다!
이제 웹사이트가 Cloudflare를 통해 제공되며, 다음과 같은 이점을 누릴 수 있습니다:
- 🚀 콘텐츠 전송 가속화
- 🛡️ DDoS 공격 방어
- 💻 캐싱을 통한 서버 부하 감소
- 🔒 무료 SSL 인증서
2️⃣ ddclient를 이용한 DDNS 설정하기 🔄
가정이나 사무실에서 동적 IP 주소로 서버를 운영할 때 DDNS(Dynamic DNS)는 필수적입니다. 클라우드 플레어와 ddclient를 이용한 DDNS 설정 방법을 알아보겠습니다.
📝 단계별 가이드
1단계: 사전 준비 📋
- Cloudflare에 도메인이 이미 연결되어 있어야 합니다.
- Linux/Unix 기반 시스템(라즈베리 파이, 우분투 서버 등)에 액세스할 수 있어야 합니다.
2단계: Cloudflare API 토큰 생성 🔑
- Cloudflare 계정에 로그인합니다.
- 우측 상단의 프로필 아이콘 → “My Profile” 클릭
- 좌측 메뉴에서 “API Tokens” 선택
- “Create Token” 버튼 클릭
- “Edit zone DNS” 템플릿 선택 또는 커스텀 토큰 생성
- 권한 설정:
- Zone Resources: 특정 도메인 또는 모든 도메인
- Permissions: Zone – DNS – Edit
- “Continue to summary” 클릭 후 “Create Token” 클릭
- 생성된 토큰을 안전한 곳에 복사해 저장합니다.
💡 TIP: API 토큰은 한 번만 표시됩니다. 꼭 안전한 곳에 저장하세요!
3단계: ddclient 설치 🖥️
다양한 Linux 배포판에서 패키지 관리자를 통해 설치할 수 있습니다:
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install ddclient
CentOS/RHEL:
sudo yum install ddclient
라즈베리 파이(Raspberry Pi OS):
sudo apt update
sudo apt install ddclient
4단계: ddclient 설정 ⚙️
- 설정 파일을 엽니다:
sudo nano /etc/ddclient.conf
- 다음 내용으로 파일을 수정합니다:
# 기본 설정
daemon=300
use=web
web=checkip.dyndns.org
web-skip='IP Address'
# Cloudflare 설정
protocol=cloudflare
zone=yourdomain.com
login=your-cloudflare-email
password=your-api-token
ttl=1
home.yourdomain.com
여기서:
yourdomain.com
→ 본인의 도메인 (예: example.com)your-cloudflare-email
→ Cloudflare 계정 이메일your-api-token
→ 2단계에서 생성한 API 토큰home.yourdomain.com
→ 업데이트할 서브도메인 (예: home.example.com)
실제 예시:
daemon=300
use=web
web=checkip.dyndns.org
web-skip='IP Address'
protocol=cloudflare
zone=example.com
[email protected]
password=0123456789abcdef0123456789abcdef
ttl=1
home.example.com
nas.example.com
이 예시에서는 home.example.com
과 nas.example.com
두 개의 서브도메인을 동시에 업데이트합니다.
5단계: ddclient 서비스 시작 및 자동 실행 설정 ▶️
# 서비스 시작
sudo systemctl start ddclient
# 부팅 시 자동 시작 설정
sudo systemctl enable ddclient
# 상태 확인
sudo systemctl status ddclient
정상적으로 실행되면 다음과 같은 출력이 표시됩니다:
● ddclient.service - Dynamic DNS Update Client
Loaded: loaded (/lib/systemd/system/ddclient.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-04-15 14:30:12 KST; 5s ago
Main PID: 12345 (ddclient)
Tasks: 1 (limit: 4915)
Memory: 4.8M
CGroup: /system.slice/ddclient.service
└─12345 /usr/sbin/ddclient -daemon 300
6단계: 수동 테스트 🧪
설정이 제대로 되었는지 확인하기 위해 수동으로 업데이트를 실행합니다:
sudo ddclient -verbose -debug -force
성공적으로 업데이트되면 다음과 같은 메시지가 표시됩니다:
SUCCESS: updating home.example.com: IP address set to 203.0.113.100
7단계: 확인하기 ✅
- Cloudflare 대시보드에서 DNS 설정을 확인합니다.
home.yourdomain.com
(또는 설정한 서브도메인)의 A 레코드가 현재 IP 주소로 업데이트되었는지 확인합니다.
이제 IP 주소가 변경될 때마다 자동으로 DNS 레코드가 업데이트됩니다!
활용 사례:
- 🏠 집에서 운영하는 홈 서버 (예: 미디어 서버, NAS)
- 💻 개인 클라우드 (예: Nextcloud)
- 🎮 게임 서버
- 📹 홈 CCTV 시스템
- 🌐 개인 VPN 서버
3️⃣ Certbot과 Cloudflare 함께 활용하기 🔒
Let’s Encrypt의 무료 SSL 인증서를 발급받기 위한 Certbot과 Cloudflare를 함께 사용하는 방법을 알아보겠습니다.
📝 단계별 가이드
1단계: Certbot 실행을 위한 Cloudflare 프록시 일시 비활성화 🔌
Let’s Encrypt가 도메인 소유권을 확인하기 위해서는 서버에 직접 접근할 수 있어야 합니다. 따라서 인증서 발급 전에 Cloudflare 프록시를 일시적으로 비활성화해야 합니다.
- Cloudflare 대시보드 로그인 → 도메인 선택
- “DNS” 탭으로 이동
- 인증서를 발급받을 도메인/서브도메인의 A 레코드 찾기
- 주황색 구름 아이콘(프록시됨) 클릭하여 회색 구름(DNS만)으로 변경
예시:
Type Name Content TTL Status
A @ 203.0.113.50 Auto 📡 DNS only (was 🌥️ Proxied)
A www 203.0.113.50 Auto 📡 DNS only (was 🌥️ Proxied)
- 변경사항이 적용될 때까지 5-10분 정도 기다립니다.
2단계: Certbot으로 SSL 인증서 발급받기 📜
- 서버에 Certbot 설치 (아직 설치하지 않았다면)
Ubuntu/Debian:
sudo apt update
sudo apt install certbot
CentOS:
sudo yum install certbot
- 웹 서버에 따라 적절한 플러그인 설치 (Apache 또는 Nginx)
Apache:
sudo apt install python3-certbot-apache
Nginx:
sudo apt install python3-certbot-nginx
- SSL 인증서 발급
Apache의 경우:
sudo certbot --apache -d example.com -d www.example.com
Nginx의 경우:
sudo certbot --nginx -d example.com -d www.example.com
웹 서버가 없거나 다른 웹 서버를 사용하는 경우:
sudo certbot certonly --standalone -d example.com -d www.example.com
- 화면의 지시에 따라 이메일 주소를 입력하고 약관에 동의합니다.
- 인증서 발급이 완료되면 성공 메시지가 표시됩니다.
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem
3단계: Cloudflare 프록시 재활성화 🔌
- Cloudflare 대시보드로 돌아갑니다.
- “DNS” 탭에서 인증서를 발급받은 도메인의 A 레코드를 찾습니다.
- 회색 구름 아이콘(DNS만)을 클릭하여 주황색 구름(프록시됨)으로 변경합니다.
Type Name Content TTL Status
A @ 203.0.113.50 Auto 🌥️ Proxied (was 📡 DNS only)
A www 203.0.113.50 Auto 🌥️ Proxied (was 📡 DNS only)
4단계: Cloudflare SSL 설정을 “가변”에서 “전체(엄격)”으로 변경 🔐
- Cloudflare 대시보드에서 “SSL/TLS” 탭으로 이동합니다.
- “개요” 섹션에서 현재 SSL 모드를 확인합니다.
- “전체(엄격)” 옵션을 선택합니다.
- “저장” 버튼을 클릭하여 변경사항을 적용합니다.
설정 모드 설명:
- 가변: Cloudflare는 방문자에게 HTTPS를 제공하지만, Cloudflare와 원본 서버 간에는 HTTP 또는 유효하지 않은 SSL 인증서도 허용합니다.
- 전체: Cloudflare와 원본 서버 간에 암호화된 연결을 요구하지만, 자체 서명된 인증서도 허용합니다.
- 전체(엄격): Cloudflare와 원본 서버 간에 유효하고 신뢰할 수 있는 SSL 인증서를 요구합니다.
“전체(엄격)” 모드는 최고 수준의 보안을 제공하며, 중간자 공격을 방지하는 데 도움이 됩니다.
5단계: 인증서 자동 갱신 설정 🔄
Let’s Encrypt 인증서는 90일마다 갱신해야 합니다. 자동 갱신을 설정하는 방법은 다음과 같습니다:
- Cron 작업 확인:
sudo systemctl status certbot.timer
- 활성화되어 있지 않다면:
sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer
- 갱신 테스트:
sudo certbot renew --dry-run
자동 갱신 시 Cloudflare 프록시 설정 자동화:
인증서 갱신 시 Cloudflare 프록시를 자동으로 비활성화했다가 다시 활성화하려면, 다음과 같은 스크립트를 만들어 사용할 수 있습니다:
- Cloudflare API 토큰 생성 (DDNS 설정 단계와 동일)
- 다음 내용으로 스크립트 파일 생성:
sudo nano /usr/local/bin/certbot-cloudflare.sh
#!/bin/bash
# Cloudflare API 설정
EMAIL="your-cloudflare-email"
API_KEY="your-global-api-key"
ZONE_ID="your-zone-id"
DOMAIN="example.com"
RECORD_ID="your-dns-record-id"
# DNS 레코드 프록시 끄기
echo "Turning off Cloudflare proxy..."
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $API_KEY" \
-H "Content-Type: application/json" \
--data '{"proxied":false}'
# DNS 변경 적용 대기
echo "Waiting for DNS changes to propagate..."
sleep 60
# Certbot 갱신 실행
echo "Renewing certificates..."
certbot renew
# DNS 레코드 프록시 다시 켜기
echo "Turning Cloudflare proxy back on..."
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $API_KEY" \
-H "Content-Type: application/json" \
--data '{"proxied":true}'
echo "Done!"
- 스크립트에 실행 권한 부여:
sudo chmod +x /usr/local/bin/certbot-cloudflare.sh
- 자동 갱신 작업 설정:
sudo crontab -e
- 다음 줄 추가 (매월 1일 오전 3시에 실행):
0 3 1 * * /usr/local/bin/certbot-cloudflare.sh
이제 인증서 갱신 과정이 완전히 자동화되었습니다! 🎉
🌟 실제 활용 사례
개인 블로그 운영 📝
- 도메인: blog.example.com
- 워드프레스 설치
- Cloudflare로 캐싱 및 방문자 분석
- Let’s Encrypt로 SSL 인증서 적용
개인 클라우드 서버 ☁️
- 도메인: cloud.example.com
- Nextcloud 또는 Owncloud 설치
- DDNS로 가정에서 운영하는 서버에 안정적으로 접속
- SSL 인증서로 데이터 보안 강화
미디어 스트리밍 서버 🎬
- 도메인: media.example.com
- Plex 또는 Emby 설치
- DDNS로 외부에서 접속 가능
- Cloudflare로 보안 강화
📚 결론
클라우드 플레어를 활용하면 도메인 관리, 동적 IP 문제 해결, SSL 인증서 관리 등 여러 문제를 효과적으로 해결할 수 있습니다. 이 블로그에서 설명한 세 가지 주요 기능을 함께 사용하면 전문적인 웹 서비스를 무료 또는 저렴한 비용으로 운영할 수 있습니다.
궁금한 점이나 추가 정보가 필요하시면 댓글로 남겨주세요! 😊
참고 자료:
Utilizing Cloudflare 🚀
Upgrade Your Website Performance and Security to the Next Level! 👨💻
Hello there! Today, I’ll be sharing detailed methods for utilizing Cloudflare, an essential tool for website operations. We’ll cover everything from connecting your domain to setting up DDNS and managing SSL certificates, explaining each process step by step. 🌐
1️⃣ Connecting Your Domain to Cloudflare 🔗
Cloudflare is a free CDN service and DNS management tool that can significantly improve your website’s speed and security. Let’s learn how to connect your domain.
📝 Step-by-Step Guide
Step 1: Create an Account and Login 📲
- Visit the Cloudflare website.
- Click the “Sign Up” button to create an account or login with your existing account.

Step 2: Add Your Domain ➕
- Click the “Add a Site” button on your dashboard.
- Enter the domain you want to connect (e.g.,
example.com
) and click “Add Site”.
💡 TIP: You should enter the root domain, not a subdomain.
Example) Correct: example.com | Incorrect: blog.example.com
Step 3: Select a Plan 💰
- Choose between the free plan or other paid plans.
- The free plan is sufficient for most personal websites.
- Click the “Continue” button.
Step 4: Verify DNS Records ✅
- Cloudflare will automatically scan and import your existing DNS records.
- Verify that all records have been imported correctly.
- Examples: A records, CNAME records, MX records, etc.
Real-World Example:
Type Name Content TTL Proxy status
A @ 203.0.113.50 Auto Proxied
CNAME www example.com Auto Proxied
MX @ mail.example.com Auto DNS only
TXT @ v=spf1 -all Auto DNS only
Add or modify records if necessary:
- If you have a blog server, add an A record:
blog 203.0.113.51 Auto Proxied
- For an email server, add an MX record:
@ 10 mail.example.com Auto DNS only
Step 5: Change Nameservers 🔄
Note down the nameserver information provided by Cloudflare.
Example:
ns1.cloudflare.com ns2.cloudflare.com
Login to your domain registrar’s management panel (e.g., GoDaddy, Namecheap, etc.)
Navigate to the nameserver settings menu.
Change the existing nameservers to those provided by Cloudflare.
Example (for GoDaddy):
- Login to GoDaddy → Domain Management → Nameservers
- Select “I’ll use my own nameservers”
- Enter Cloudflare nameservers:
ns1.cloudflare.comns2.cloudflare.com
- Save changes
Step 6: Verify Nameserver Change and Activation 🟢
- Nameserver changes can take up to 24 hours to propagate (usually completes within a few hours).
- Check the status on your Cloudflare dashboard.
- When you see “Status: Active”, your domain has been successfully connected!
Now your website is being served through Cloudflare, and you can enjoy benefits like:
- 🚀 Accelerated content delivery
- 🛡️ DDoS attack protection
- 💻 Reduced server load through caching
- 🔒 Free SSL certificate
2️⃣ Setting Up DDNS with ddclient 🔄
When running a server at home or in an office with a dynamic IP address, DDNS (Dynamic DNS) is essential. Let’s explore how to set up DDNS using Cloudflare and ddclient.
📝 Step-by-Step Guide
Step 1: Prerequisites 📋
- Your domain should already be connected to Cloudflare.
- You need access to a Linux/Unix-based system (Raspberry Pi, Ubuntu server, etc.)
Step 2: Generate a Cloudflare API Token 🔑
- Login to your Cloudflare account.
- Click on your profile icon in the top-right corner → “My Profile”
- Select “API Tokens” from the left menu
- Click the “Create Token” button
- Select the “Edit zone DNS” template or create a custom token
- Set permissions:
- Zone Resources: Specific domain or all domains
- Permissions: Zone – DNS – Edit
- Click “Continue to summary” then “Create Token”
- Copy and save the generated token in a secure location.
💡 TIP: API tokens are only displayed once. Make sure to save it securely!
Step 3: Install ddclient 🖥️
You can install it via package managers on various Linux distributions:
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install ddclient
CentOS/RHEL:
sudo yum install ddclient
Raspberry Pi (Raspberry Pi OS):
sudo apt update
sudo apt install ddclient
Step 4: Configure ddclient ⚙️
- Open the configuration file:
sudo nano /etc/ddclient.conf
- Modify the file with the following content:
# Basic configuration
daemon=300
use=web
web=checkip.dyndns.org
web-skip='IP Address'
# Cloudflare configuration
protocol=cloudflare
zone=yourdomain.com
login=your-cloudflare-email
password=your-api-token
ttl=1
home.yourdomain.com
Where:
yourdomain.com
→ Your domain (e.g., example.com)your-cloudflare-email
→ Your Cloudflare account emailyour-api-token
→ API token created in Step 2home.yourdomain.com
→ Subdomain to update (e.g., home.example.com)
Real-World Example:
daemon=300
use=web
web=checkip.dyndns.org
web-skip='IP Address'
protocol=cloudflare
zone=example.com
[email protected]
password=0123456789abcdef0123456789abcdef
ttl=1
home.example.com
nas.example.com
In this example, we’re updating two subdomains simultaneously: home.example.com
and nas.example.com
.
Step 5: Start ddclient Service and Set Automatic Startup ▶️
# Start the service
sudo systemctl start ddclient
# Set to start automatically on boot
sudo systemctl enable ddclient
# Check status
sudo systemctl status ddclient
If running correctly, you should see output like this:
● ddclient.service - Dynamic DNS Update Client
Loaded: loaded (/lib/systemd/system/ddclient.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-04-15 14:30:12 UTC; 5s ago
Main PID: 12345 (ddclient)
Tasks: 1 (limit: 4915)
Memory: 4.8M
CGroup: /system.slice/ddclient.service
└─12345 /usr/sbin/ddclient -daemon 300
Step 6: Manual Testing 🧪
Run a manual update to confirm your settings are working correctly:
sudo ddclient -verbose -debug -force
If successful, you’ll see a message like:
SUCCESS: updating home.example.com: IP address set to 203.0.113.100
Step 7: Verification ✅
- Check the DNS settings in your Cloudflare dashboard.
- Verify that the A record for
home.yourdomain.com
(or your configured subdomain) has been updated to your current IP address.
Now your DNS record will automatically update whenever your IP address changes!
Use Cases:
- 🏠 Home servers (e.g., media servers, NAS)
- 💻 Personal cloud (e.g., Nextcloud)
- 🎮 Game servers
- 📹 Home CCTV systems
- 🌐 Personal VPN servers
3️⃣ Using Certbot with Cloudflare 🔒
Let’s explore how to use Certbot with Cloudflare to obtain free SSL certificates from Let’s Encrypt.
📝 Step-by-Step Guide
Step 1: Temporarily Disable Cloudflare Proxy for Certbot 🔌
Let’s Encrypt needs to access your server directly to verify domain ownership. Therefore, you need to temporarily disable the Cloudflare proxy before obtaining the certificate.
- Login to Cloudflare dashboard → Select your domain
- Go to the “DNS” tab
- Find the A record for the domain/subdomain you want to get a certificate for
- Click the orange cloud icon (Proxied) to change it to a gray cloud (DNS only)
Example:
Type Name Content TTL Status
A @ 203.0.113.50 Auto 📡 DNS only (was 🌥️ Proxied)
A www 203.0.113.50 Auto 📡 DNS only (was 🌥️ Proxied)
- Wait about 5-10 minutes for the changes to take effect.
Step 2: Obtain SSL Certificate with Certbot 📜
- Install Certbot on your server (if not already installed)
Ubuntu/Debian:
sudo apt update
sudo apt install certbot
CentOS:
sudo yum install certbot
- Install the appropriate plugin for your web server (Apache or Nginx)
Apache:
sudo apt install python3-certbot-apache
Nginx:
sudo apt install python3-certbot-nginx
- Obtain the SSL certificate
For Apache:
sudo certbot --apache -d example.com -d www.example.com
For Nginx:
sudo certbot --nginx -d example.com -d www.example.com
For standalone mode (if you don’t have a web server or use a different one):
sudo certbot certonly --standalone -d example.com -d www.example.com
- Follow the on-screen instructions to enter your email address and agree to the terms.
- When the certificate issuance is complete, you’ll see a success message.
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem
Step 3: Re-enable Cloudflare Proxy 🔌
- Return to your Cloudflare dashboard.
- In the “DNS” tab, find the A record for your domain.
- Click the gray cloud icon (DNS only) to change it back to an orange cloud (Proxied).
Type Name Content TTL Status
A @ 203.0.113.50 Auto 🌥️ Proxied (was 📡 DNS only)
A www 203.0.113.50 Auto 🌥️ Proxied (was 📡 DNS only)
Step 4: Change Cloudflare SSL Setting from “Flexible” to “Full (Strict)” 🔐
- Go to the “SSL/TLS” tab in your Cloudflare dashboard.
- Check the current SSL mode in the “Overview” section.
- Select the “Full (Strict)” option.
- Click the “Save” button to apply the changes.
SSL Mode Descriptions:
- Flexible: Cloudflare provides HTTPS to visitors but allows HTTP or invalid SSL certificates between Cloudflare and your origin server.
- Full: Requires encrypted connection between Cloudflare and your origin server but allows self-signed certificates.
- Full (Strict): Requires a valid, trusted SSL certificate between Cloudflare and your origin server.
“Full (Strict)” mode provides the highest level of security and helps prevent man-in-the-middle attacks.
Step 5: Set Up Automatic Certificate Renewal 🔄
Let’s Encrypt certificates must be renewed every 90 days. Here’s how to set up automatic renewal:
- Check the Cron job status:
sudo systemctl status certbot.timer
- If not active:
sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer
- Test renewal:
sudo certbot renew --dry-run
Automating Cloudflare Proxy Settings During Renewal:
To automatically disable and re-enable the Cloudflare proxy during certificate renewal, you can create a script:
- Generate a Cloudflare API token (same as in the DDNS setup section)
- Create a script file with the following content:
sudo nano /usr/local/bin/certbot-cloudflare.sh
#!/bin/bash
# Cloudflare API settings
EMAIL="your-cloudflare-email"
API_KEY="your-global-api-key"
ZONE_ID="your-zone-id"
DOMAIN="example.com"
RECORD_ID="your-dns-record-id"
# Turn off DNS record proxy
echo "Turning off Cloudflare proxy..."
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $API_KEY" \
-H "Content-Type: application/json" \
--data '{"proxied":false}'
# Wait for DNS changes to propagate
echo "Waiting for DNS changes to propagate..."
sleep 60
# Run Certbot renewal
echo "Renewing certificates..."
certbot renew
# Turn DNS record proxy back on
echo "Turning Cloudflare proxy back on..."
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $API_KEY" \
-H "Content-Type: application/json" \
--data '{"proxied":true}'
echo "Done!"
- Make the script executable:
sudo chmod +x /usr/local/bin/certbot-cloudflare.sh
- Set up an automatic renewal task:
sudo crontab -e
- Add the following line (runs at 3 AM on the 1st of every month):
0 3 1 * * /usr/local/bin/certbot-cloudflare.sh
Now your certificate renewal process is fully automated! 🎉
🌟 Real-World Use Cases
Personal Blog 📝
- Domain: blog.example.com
- WordPress installation
- Caching and visitor analytics with Cloudflare
- SSL certificate via Let’s Encrypt
Personal Cloud Server ☁️
- Domain: cloud.example.com
- Nextcloud or Owncloud installation
- Reliable access to a home-hosted server via DDNS
- Enhanced data security with SSL certificates
Media Streaming Server 🎬
- Domain: media.example.com
- Plex or Emby installation
- External access via DDNS
- Enhanced security with Cloudflare
📚 Conclusion
By utilizing Cloudflare, you can effectively solve various issues such as domain management, dynamic IP problems, and SSL certificate management. By using the three main features explained in this blog together, you can operate professional web services for free or at a low cost.
If you have any questions or need additional information, please leave a comment below! 😊
References: