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

Localhost के लिए HTTPS: Local Development के लिए SSL Certificate

Modern web APIs (service workers, geolocation, clipboard, camera) को HTTPS की need होती है — development के दौरान भी। यह guide बताती है कि browser warnings के बिना localhost पर trusted HTTPS कैसे get करें।

आप Localhost के लिए Let’s Encrypt Use क्यों नहीं कर सकते

Let’s Encrypt आपके server पर एक file या DNS record check करके domain ownership verify करता है। localhost एक real domain नहीं है — यह सिर्फ आपकी machine पर 127.0.0.1 पर resolve होता है। कोई भी verify नहीं कर सकता कि आप localhost के “owner” हैं, इसलिए कोई भी public CA इसके लिए certificate issue नहीं करेगा।

Localhost HTTPS के लिए आपके options:

  1. mkcert — locally trusted certificates बनाता है (recommended)
  2. Self-signed certificate — काम करता है लेकिन browser warning दिखाता है
  3. Tunneling service — ngrok, Cloudflare Tunnel (real domain, real cert)

mkcert आपकी machine पर एक local Certificate Authority बनाता है, इसे आपके system trust store में add करता है, और उस CA द्वारा signed certificates issue करता है। Browsers इन certificates पर बिना किसी warning के trust करते हैं।

mkcert Install करें

# macOS
brew install mkcert

# Linux (requires libnss3-tools for Firefox)
sudo apt install libnss3-tools
brew install mkcert  # or download from GitHub releases

# Windows
choco install mkcert
# or: scoop install mkcert

Local CA Set करें

mkcert -install
# Output: Created a new local CA
# The local CA is now installed in the system trust store

यह आपके system और browser trust store में एक root certificate add करता है। यह एक बार करें — यह सभी future certificates के लिए काम करता है।

Certificate Generate करें

# For localhost
mkcert localhost 127.0.0.1 ::1

# For a custom local domain
mkcert myapp.test "*.myapp.test" localhost 127.0.0.1

# Output:
# Created a new certificate valid for the following names:
#  - "localhost"
#  - "127.0.0.1"
#  - "::1"
# The certificate is at "./localhost+2.pem" and the key at "./localhost+2-key.pem"

अपने Dev Server के साथ Use करें

Node.js/Express:

const https = require('https');
const fs = require('fs');
const app = require('./app');

https.createServer({
  key: fs.readFileSync('./localhost+2-key.pem'),
  cert: fs.readFileSync('./localhost+2.pem'),
}, app).listen(3000);

Nginx (local):

server {
    listen 443 ssl;
    server_name localhost;
    ssl_certificate     /path/to/localhost+2.pem;
    ssl_certificate_key /path/to/localhost+2-key.pem;
    # ...
}

Vite / webpack dev server:

// vite.config.js
import fs from 'fs';
export default {
  server: {
    https: {
      key: fs.readFileSync('./localhost+2-key.pem'),
      cert: fs.readFileSync('./localhost+2.pem'),
    },
  },
};

Security Warning

mkcert root CA key कभी share न करें (mkcert -CAROOT में rootCA-key.pem)। जिसके पास यह है वह आपकी machine पर किसी भी domain के लिए trusted certificate बना सकता है — essentially एक local man-in-the-middle capability।

mkcert सिर्फ development के लिए है। Production के लिए, Let’s Encrypt use करें।

Option 2: Self-signed Certificate

अगर आप mkcert install नहीं कर सकते, तो OpenSSL के साथ एक self-signed certificate generate करें:

openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 \
  -keyout localhost-key.pem -out localhost-cert.pem \
  -days 365 -nodes -subj "/CN=localhost" \
  -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"

Downside: Browsers एक security warning दिखाते हैं क्योंकि self-signed certificates पर कोई CA trust नहीं करता। आपको हर बार warning click करके bypass करना होगा (या एक exception add करनी होगी)।

Option 3: Tunneling (Real Domain + Real Certificate)

अपने local server को real domain और certificate के साथ expose करने के लिए tunneling service use करें:

# ngrok
ngrok http 3000
# Gives you: https://abc123.ngrok.io

# Cloudflare Tunnel
cloudflared tunnel --url http://localhost:3000
# Gives you: https://random-name.trycloudflare.com

यह कब make sense करता है: webhook testing, teammate के साथ share करना, HTTPS required OAuth callback testing।

mkcert vs Self-signed vs Tunneling

mkcertSelf-signedTunneling
Browser warningNoneहां (हर session)None
Setup effortLow (एक install)Low (एक command)Low
Offline काम करता हैहांहांनहीं
PerformanceLocal speedLocal speedNetwork latency
Custom domainsहां (*.test, etc.)हांProvider-specific
Best forDaily developmentQuick one-offWebhooks, sharing

FAQ

क्या मैं अपनी team में same mkcert certificate use कर सकता हूं?

Root CA key share न करें। हर developer को अपनी machine पर अपना खुद का local CA बनाने के लिए mkcert -install run करना चाहिए। आप generated certificates (.pem files) share कर सकते हैं, लेकिन हर person को उन पर trust करने के लिए CA install करना होगा।

क्या mkcert Docker के साथ काम करता है?

हां। Certificate files को container में mount करें और server config में उनका reference दें। Container को खुद mkcert install करने की need नहीं है — बस .pem files। आपकी host machine (जहां browser run होता है) को mkcert CA install करना होगा।

मुझे कौन सा local domain use करना चाहिए?

.test use करें (जैसे, myapp.test) — यह IETF द्वारा testing के लिए reserved है और कभी भी real domain से clash नहीं करेगा। .dev (Google owned) और .local (mDNS द्वारा used) से avoid करें। अपने .test domain को 127.0.0.1 पर point करने के लिए /etc/hosts में एक entry add करें।

मैं localhost HTTPS से production HTTPS पर कैसे switch करूं?

ये पूरी तरह से different हैं। आपका localhost certificate (mkcert/self-signed) आपकी dev machine पर रहता है। Production के लिए, GetHTTPS के through Let’s Encrypt से real certificate get करें। आपके code को environment variables से cert paths read करने चाहिए ताकि switch सिर्फ एक config change हो।

संबंधित लेख

शुरुआत करें 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-08
Node.js के साथ SSL Certificate कैसे Use करें
Node.js और Express में HTTPS configure करें। PEM certificate files load करें, TLS options set करें, और development व production दोनों में SSL handle करें।
डिप्लॉयमेंट 2026-05-08
Docker और Reverse Proxy के साथ SSL Certificate
Nginx reverse proxy, automatic Let's Encrypt के साथ Traefik, या manual certificate mounting use करके Docker containers के लिए HTTPS configure करें।
अपने browser में मुफ़्त SSL certificate पाएँ
कोई installation नहीं, कोई account नहीं। आपकी private key कभी आपका device नहीं छोड़ती।
अपना certificate पाएँ