सभी डिप्लॉयमेंट गाइड डिप्लॉयमेंट

Nginx पर SSL Certificate कैसे Install करें

यह guide Nginx पर SSL certificate install करने की process बताती है — files upload करने से लेकर TLS settings optimize करने और common errors troubleshoot करने तक। यह GetHTTPS, Certbot, या किसी भी source के certificates के साथ काम करती है।

अगर आपके पास अभी तक certificate नहीं है, तो 5 मिनट में free में get करें

Requirements

  • Nginx installed और HTTP (port 80) पर आपकी site serve कर रहा है
  • Server पर Root/sudo access
  • Certificate files — आपको दो चाहिए:
    • fullchain.pem — आपका certificate + intermediate chain (combined)
    • privkey.pem — आपकी private key

कौन सी file कौन सी है? GetHTTPS आपको चार files देता है। Nginx को fullchain.pem (cert.pem नहीं) और privkey.pem चाहिए। अकेले cert.pem use करना “incomplete chain” errors cause करता है क्योंकि browsers trust path verify नहीं कर सकते। Certificate format explained —>

Step 1: Certificate Files Server पर Upload करें

Files को एक secure directory में copy करें:

# Create directory
sudo mkdir -p /etc/ssl/gethttps

# Copy files (from your local machine to the server)
sudo cp fullchain.pem /etc/ssl/gethttps/
sudo cp privkey.pem /etc/ssl/gethttps/

# Restrict private key permissions — only root should read it
sudo chmod 600 /etc/ssl/gethttps/privkey.pem
sudo chmod 644 /etc/ssl/gethttps/fullchain.pem
sudo chown root:root /etc/ssl/gethttps/*

अगर SCP से transfer कर रहे हैं:

scp fullchain.pem privkey.pem user@your-server:/tmp/
# Then on the server:
sudo mv /tmp/fullchain.pem /tmp/privkey.pem /etc/ssl/gethttps/

Step 2: HTTPS Server Block Configure करें

अपनी site का Nginx configuration edit करें। File usually यहां होती है:

  • /etc/nginx/sites-available/yourdomain.conf (Debian/Ubuntu)
  • /etc/nginx/conf.d/yourdomain.conf (CentOS/RHEL)

Full recommended configuration:

# HTTPS server block
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com www.example.com;

    # ─── Certificate files ───────────────────────
    ssl_certificate     /etc/ssl/gethttps/fullchain.pem;
    ssl_certificate_key /etc/ssl/gethttps/privkey.pem;

    # ─── TLS protocol and ciphers ────────────────
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers off;

    # ─── Session caching (performance) ───────────
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;
    ssl_session_tickets off;

    # ─── OCSP stapling (faster verification) ─────
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8 8.8.4.4 valid=300s;
    resolver_timeout 5s;

    # ─── Security headers ────────────────────────
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Frame-Options "SAMEORIGIN" always;

    # ─── Your site ───────────────────────────────
    root /var/www/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

# HTTP redirect block
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

हर section क्या करता है:

DirectivePurpose
listen 443 ssl http2HTTP/2 enabled के साथ port 443 पर HTTPS
ssl_certificateआपके certificate + chain का path
ssl_certificate_keyआपकी private key का path
ssl_protocolsसिर्फ TLS 1.2 और 1.3 (1.0/1.1 2020 से deprecated)
ssl_prefer_server_ciphers offClient को best cipher choose करने दें (modern best practice)
ssl_session_cacheTLS sessions cache करें — returning visitors के लिए re-handshake avoid करें
ssl_session_tickets offTickets forward secrecy को weaken कर सकते हैं
ssl_staplingServer OCSP response fetch करता है — client के लिए faster
Strict-Transport-SecurityHSTS — browser हमेशा HTTPS use करना remember करते हैं
return 301HTTP से HTTPS पर permanent redirect

Step 3: Configuration Test करें

Reload करने से पहले हमेशा test करें:

sudo nginx -t

Expected output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

अगर test fail होता है, तो Nginx आपको error वाली exact line number बताता है। Common mistakes:

  • File path में typo (ssl_certifcate बजाय ssl_certificate)
  • Specified path पर file exist नहीं है
  • Missing semicolon

Step 4: Nginx Reload करें

sudo systemctl reload nginx

restart नहीं, reload use करें। Reload existing connections drop किए बिना नए connections पर नया configuration apply करता है — zero downtime।

Step 5: Certificate Verify करें

Browser Check

https://yourdomain.com पर जाएं। Confirm करने के लिए padlock icon पर click करें:

  • Issued by: “Let’s Encrypt” (या आपका CA)
  • Valid: start और expiry dates
  • Domain: आपके URL से match करता है

Command-line Check

# Full certificate details
echo | openssl s_client -connect yourdomain.com:443 -servername yourdomain.com 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates -ext subjectAltName

# Check the full chain is present
echo | openssl s_client -connect yourdomain.com:443 -servername yourdomain.com 2>/dev/null \
  | grep -E 'Verify return code|depth='

Expected: Verify return code: 0 (ok) और multiple depth levels (आपका cert + intermediate)।

Online Check

Comprehensive report के लिए SSL Labs Server Test use करें। यह check करता है:

  • Certificate chain validity
  • Protocol support (सिर्फ TLS 1.2 + 1.3 दिखना चाहिए)
  • Cipher suite strength
  • Known vulnerabilities (BEAST, POODLE, Heartbleed)
  • HSTS configuration

Target: Grade A या A+।

Renewal कैसे करें

जब आपका certificate expiry के करीब पहुंचे (Let’s Encrypt के लिए 90 में से day 60):

  1. GetHTTPS (या आपके renewal tool) से नया certificate get करें
  2. Files replace करें:
    sudo cp new-fullchain.pem /etc/ssl/gethttps/fullchain.pem
    sudo cp new-privkey.pem /etc/ssl/gethttps/privkey.pem
  3. Nginx reload करें:
    sudo systemctl reload nginx

Restart की need नहीं। Nginx reload पर नई files pick up करता है। Full renewal guide —>

Automated renewal चाहिए? Hands-off renewal के लिए Certbot install करें: sudo certbot --nginx -d example.com। यह Nginx config सहित सब कुछ handle करता है।

Troubleshooting

”SSL: error:0B080074:x509 certificate routines”

Reason: आप fullchain.pem की बजाय cert.pem use कर रहे हैं।

Fix: ssl_certificate को fullchain.pem पर point करने के लिए change करें, जिसमें आपका certificate और intermediate chain of trust दोनों included हैं:

ssl_certificate /etc/ssl/gethttps/fullchain.pem;  # NOT cert.pem

“cannot load certificate key”

Reason: Private key file की permissions wrong हैं, file corrupt है, या key certificate से match नहीं करती।

Fix:

# Check permissions (should be 600)
ls -la /etc/ssl/gethttps/privkey.pem

# Verify the key is valid
sudo openssl ec -in /etc/ssl/gethttps/privkey.pem -check  # For ECDSA
sudo openssl rsa -in /etc/ssl/gethttps/privkey.pem -check  # For RSA

# Verify key matches certificate
sudo openssl x509 -noout -modulus -in /etc/ssl/gethttps/fullchain.pem | md5sum
sudo openssl rsa -noout -modulus -in /etc/ssl/gethttps/privkey.pem | md5sum
# Both hashes MUST match

“nginx: [emerg] bind() to 0.0.0.0:443 failed”

Reason: Port 443 पहले से किसी other process द्वारा use में है।

Fix:

# Find what's using port 443
sudo ss -tlnp | grep 443

# Usually: another Nginx instance or Apache
sudo systemctl stop apache2  # If Apache is running
sudo systemctl reload nginx

HTTPS काम करता है लेकिन browser “Not Secure” दिखाता है

Reason: Mixed content — आपका page http:// पर images, scripts, या CSS load करता है।

Fix: DevTools (F12) → Console खोलें → “Mixed Content” warnings find करें। सभी resource URLs को https:// या relative paths use करने के लिए update करें।

“ERR_SSL_VERSION_OR_CIPHER_MISMATCH”

Reason: Client आपके server द्वारा offer किए गए TLS versions या ciphers support नहीं करता।

Fix: Ensure करें कि आपके config में TLS 1.2 included है (सिर्फ 1.3 नहीं):

ssl_protocols TLSv1.2 TLSv1.3;  # NOT just TLSv1.3

Correct files के बावजूद certificate “Untrusted” दिखता है

Reason: Certificate chain incomplete है — fullchain.pem में intermediate certificate missing है, या file wrong order में है।

Fix: अपना cert + intermediate combine करके fullchain.pem फिर से बनाएं:

cat cert.pem chain.pem > fullchain.pem

Order matter करता है: पहले आपका certificate, फिर intermediate।

FAQ

क्या मुझे HTTP और HTTPS के लिए अलग config files चाहिए?

नहीं। दोनों server blocks (port 80 और 443) एक ही file में रखें। HTTP block सिर्फ HTTPS पर redirect करने के लिए exist करता है।

क्या मुझे ssl on; use करना चाहिए?

नहीं। ssl on; deprecated है। इसके बजाय listen 443 ssl; use करें — listen directive में ssl parameter modern तरीका है।

reload और restart में क्या difference है?

reload existing connections drop किए बिना नए connections पर नया config gracefully apply करता है। restart process को stop और start करता है, briefly सभी connections drop करता है। Certificate changes के लिए हमेशा reload use करें।

क्या मैं different certificates के साथ multiple domains serve कर सकता हूं?

हां। अलग-अलग server_name, ssl_certificate, और ssl_certificate_key directives के साथ separate server blocks use करें। Nginx requested hostname के basis पर correct certificate serve करने के लिए SNI (Server Name Indication) use करता है।

क्या Nginx ECDSA/ECC certificates support करता है?

हां। Nginx ECDSA certificates को exactly RSA की तरह handle करता है — same directives, same file format। GetHTTPS default रूप से ECDSA P-256 generate करता है (smaller keys, faster handshakes)।

HTTP/2 कैसे enable करें?

listen directive में http2 add करें: listen 443 ssl http2;। यह ऊपर के recommended config में पहले से है। HTTP/2 को HTTPS की need है — आप इसे plain HTTP पर use नहीं कर सकते।

संबंधित लेख

शुरुआत करें 2026-05-08
Free SSL certificate कैसे पाएं (step-by-step guide)
Let's Encrypt से 5 minutes में free SSL certificate पाएं — कोई software install नहीं, कोई account नहीं बनाना। 4 methods, दोनों challenge types, 6 platforms पर installation, और troubleshooting cover करने वाली complete guide।
डिप्लॉयमेंट 2026-05-07
HTTP से HTTPS पर Redirect कैसे करें
Server-side redirect के साथ सारा traffic HTTPS पर force करें। 301 permanent redirect के साथ Nginx, Apache, और .htaccess के लिए configuration examples।
डिप्लॉयमेंट 2026-05-08
Apache पर SSL Certificate कैसे Install करें
mod_ssl के साथ Apache पर SSL certificate install करने की step-by-step guide। File upload, VirtualHost config, TLS best practices, HSTS, HTTP redirect, और 5 common errors का solution शामिल है।
डिप्लॉयमेंट 2026-05-07
Mixed Content Warnings कैसे Fix करें
Mixed content तब होता है जब एक HTTPS page HTTP पर resources load करता है। Mixed content errors को find और fix करने का तरीका जानें ताकि आपको clean padlock icon मिले।
अपने browser में मुफ़्त SSL certificate पाएँ
कोई installation नहीं, कोई account नहीं। आपकी private key कभी आपका device नहीं छोड़ती।
अपना certificate पाएँ