ssl-guides 2026-12-02 ⏱ 1 min read

Docker के साथ Let's Encrypt

Docker के साथ Let's Encrypt
छोटा जवाब: Docker के साथ Let's Encrypt इंस्टॉल करने के लिए Nginx को कंटेनर में चलाएँ और /etc/letsencrypt तथा webroot के लिए साझा वॉल्यूम दें, आधिकारिक Certbot इमेज से सर्टिफिकेट माँगें, Nginx को नई फ़ाइलों पर पॉइंट करें, और certbot renew के साथ Nginx रीलोड से रिन्यू करें।

शुरू करने से पहले

  • डोमेन का DNS आपके Docker होस्ट की ओर इशारा करता है। DNS Lookup से जाँचें।
  • पोर्ट 80 और 443 होस्ट पर खुले हैं और कंटेनर उन्हें पब्लिश करता है।
  • आप असली डोमेन इस्तेमाल करते हैं, localhost नहीं।

Compose फ़ाइल

services:
  nginx:
    image: nginx:stable
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
      - ./certbot/www:/var/www/certbot:ro
      - ./certbot/conf:/etc/letsencrypt:ro
    restart: unless-stopped

  certbot:
    image: certbot/certbot
    volumes:
      - ./certbot/www:/var/www/certbot
      - ./certbot/conf:/etc/letsencrypt

कदम 1: चैलेंज पास करने के लिए सिर्फ़ HTTP पर Nginx

server {
    listen 80;
    server_name example.com www.example.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }
    location / {
        return 301 https://$host$request_uri;
    }
}

docker compose up -d nginx से शुरू करें।

Docker के साथ Let's Encrypt: सर्टिफिकेट माँगना

docker compose run --rm certbot certonly --webroot -w /var/www/certbot \
  -d example.com -d www.example.com --email admin@example.com --agree-tos

प्रयोग करते समय रेट लिमिट से बचने के लिए पहले --dry-run से टेस्ट करें। अगर कंटेनर नहीं चलाना चाहते, तो TryFreeSSL.com पर सर्टिफिकेट जारी करके फ़ाइलें कॉपी कर सकते हैं।

कदम 3: Nginx में HTTPS चालू करना

उसी कॉन्फ़िग में 443 पर एक सर्वर ब्लॉक जोड़ें। Nginx कंटेनर को उसे देखने के लिए रीस्टार्ट या रीलोड करना होगा।

server {
    listen 443 ssl;
    server_name example.com www.example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;

    location / {
        proxy_pass http://app:3000;
    }
}
docker compose exec nginx nginx -t && docker compose exec nginx nginx -s reload

Docker के साथ Let's Encrypt: रिन्यूअल

इसे होस्ट पर शेड्यूल करें, जैसे cron में दिन में दो बार:

0 3,15 * * * cd /srv/app && docker compose run --rm certbot renew --quiet && docker compose exec -T nginx nginx -s reload

docker compose run --rm certbot renew --dry-run से टेस्ट करें। Certbot ऑटोमेशन गाइड भी देखें।

आम दिक्कतें

दिक्कतहल
चैलेंज 404 देता हैदेखें कि दोनों कंटेनर एक ही webroot वॉल्यूम साझा करते हैं और पाथ मेल खाता है
Nginx शुरू नहीं होता, फ़ाइल नहीं मिलीसर्टिफिकेट बनने से पहले 443 ब्लॉक न जोड़ें
सर्टिफिकेट फ़ाइलें पढ़ी नहीं जातींफ़ोल्डर माउंट करें और देखें कि live के सिंबॉलिक लिंक कंटेनर के अंदर रिज़ॉल्व होते हैं
रिन्यूअल चलता है पर साइट पुराना सर्टिफिकेट दिखाती हैरिन्यूअल के बाद Nginx रीलोड करें

नतीजा SSL Checker से जाँचें।

और पढ़ें: Docker में SSL की पूरी गाइड, रिन्यूअल और रीलोड अपने आप करना और Kubernetes क्लस्टर में सर्टिफिकेट।

अक्सर पूछे जाने वाले सवाल

क्या ऐसा रिवर्स प्रॉक्सी इस्तेमाल कर सकते हैं जो यह सब कर दे?

हाँ। Traefik और Caddy सर्टिफिकेट अपने आप माँगते और रिन्यू करते हैं। Caddy vs Traefik vs Nginx देखें।

सर्टिफिकेट इमेज में क्यों न रखें?

वे एक्सपायर होते हैं और सीक्रेट रखते हैं। उन्हें वॉल्यूम में रखें।

क्या wildcard मिल सकता है?

हाँ, DNS चैलेंज और उससे मेल खाने वाली Certbot DNS प्लगइन इमेज से।

क्या Certbot कंटेनर चलता रहता है?

नहीं। वह ज़रूरत पर चलता है और खत्म हो जाता है।

Docker में चैलेंज क्यों फ़ेल होता है?

क्योंकि वैलिडेशन रिक्वेस्ट उस सर्वर तक पहुँचती है जो टोकन रखने वाला कंटेनर नहीं है। पोर्ट मैपिंग देखें और देखें कि webroot वॉल्यूम वही है जो Nginx असल में सर्व करता है।

सर्टिफिकेट कहाँ रहने चाहिए?

एक नामित वॉल्यूम में, जो Certbot और Nginx दोनों कंटेनर में माउंट हो। कंटेनर के अंदर लिखी फ़ाइलें उसे दोबारा बनाने पर चली जाती हैं, और अचानक एक्सपायरी की आम वजह यही है।

Nginx नया सर्टिफिकेट कैसे उठाता है?

रीलोड के बिना नहीं। रिन्यूअल के बाद रीलोड चलाएँ, Certbot कंटेनर से deploy hook के ज़रिए या होस्ट से docker exec nginx nginx -s reload से।

क्या Docker के साथ DNS वैलिडेशन हो सकता है?

हाँ, और यह तब आसान है जब पोर्ट 80 पब्लिश न हो। क्लाइंट को कंटेनर के अंदर DNS क्रेडेंशियल चाहिए, इसलिए उन्हें इमेज में डालने के बजाय एनवायरनमेंट वेरिएबल से दें।

🔒 Test Your Website SSL Certificate Now
Run Free SSL Check →

✅ Post-Installation Verification & SEO Checklist

After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:

  • Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
  • Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
  • Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
  • Confirm both root and www versions resolve cleanly to one canonical HTTPS URL.
  • Verify your HTTPS property and sitemap.xml inside Google Search Console and Bing Webmaster Tools.
Technically Reviewed by TryFreeSSL Security Team
Last updated: 2026-12-05
About Us →

मुफ़्त SSL सर्टिफ़िकेट, लाइव SSL चेकर और CSR जनरेटर

बिना किसी सर्वर सेटअप के 60 सेकंड में Let's Encrypt और Buypass SSL प्राप्त करें।

Related Articles

🤖 TryFreeSSL AI Assistant