यह guide आपको mod_ssl use करके Apache HTTP Server पर SSL certificate install करने की पूरी process बताती है — files upload करने से लेकर strict TLS settings और common errors के solution तक। GetHTTPS, Certbot, या किसी भी CA के certificate के साथ काम करती है।
अगर आपके पास अभी तक certificate नहीं है, तो 5 मिनट में free में पाएं।
Requirements
- Apache 2.4+ install और HTTP (port 80) पर आपकी site serve कर रहा हो
- Root/sudo access server पर
- Certificate files — Apache को तीन अलग-अलग files चाहिए:
cert.pem— आपका certificate (सिर्फ end-entity)privkey.pem— आपकी private keychain.pem— intermediate CA certificate chain
तीन files क्यों? Nginx (जो एक ही
fullchain.pemuse करता है) के opposite, Apache traditionally certificate और chain को अलग-अलग files के रूप में चाहता है। Apache 2.4.8+ मेंSSLCertificateFileमेंfullchain.pemuse किया जा सकता है औरSSLCertificateChainFileको skip किया जा सकता है। Format details →
Step 1: Certificate Files Upload करें
# एक secure directory बनाएं
sudo mkdir -p /etc/ssl/gethttps
# Files server पर copy करें
sudo cp cert.pem chain.pem privkey.pem /etc/ssl/gethttps/
# Private key को lock करें
sudo chmod 600 /etc/ssl/gethttps/privkey.pem
sudo chmod 644 /etc/ssl/gethttps/cert.pem /etc/ssl/gethttps/chain.pem
sudo chown root:root /etc/ssl/gethttps/*
अगर SCP से transfer कर रहे हैं:
scp cert.pem chain.pem privkey.pem user@your-server:/tmp/
# Server पर:
sudo mv /tmp/{cert,chain,privkey}.pem /etc/ssl/gethttps/
Step 2: Required Apache Modules Enable करें
# Debian/Ubuntu
sudo a2enmod ssl # Core SSL module
sudo a2enmod headers # HSTS और security headers के लिए
sudo a2enmod rewrite # HTTP→HTTPS redirect के लिए (.htaccess use करते समय)
sudo systemctl restart apache2
# CentOS/RHEL/Amazon Linux
sudo yum install mod_ssl # आमतौर पर एक ही step में install और enable करता है
sudo systemctl restart httpd
Verify करें कि mod_ssl loaded है:
apachectl -M | grep ssl
# Expected: ssl_module (shared)
Step 3: HTTPS VirtualHost Configure करें
अपनी site का SSL config बनाएं या edit करें। Debian/Ubuntu पर, यह आमतौर पर /etc/apache2/sites-available/yourdomain-ssl.conf होता है:
# ─── HTTPS server ────────────────────────────
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
# Certificate files
SSLEngine on
SSLCertificateFile /etc/ssl/gethttps/cert.pem
SSLCertificateKeyFile /etc/ssl/gethttps/privkey.pem
SSLCertificateChainFile /etc/ssl/gethttps/chain.pem
# TLS protocol — सिर्फ 1.2 और 1.3
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLHonorCipherOrder off
SSLCompression off
# OCSP stapling (client के लिए faster certificate verification)
SSLUseStapling on
SSLStaplingCache "shmcb:/var/run/apache2/ssl_stapling(128000)"
# Security headers
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
# आपकी site
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
</Directory>
</VirtualHost>
# ─── HTTP redirect ───────────────────────────
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
हर directive क्या करता है:
| Directive | Purpose |
|---|---|
SSLEngine on | इस VirtualHost के लिए SSL/TLS enable करता है |
SSLCertificateFile | आपके certificate का path |
SSLCertificateKeyFile | आपकी private key का path |
SSLCertificateChainFile | Intermediate CA certificate का path |
SSLProtocol | सिर्फ TLS 1.2/1.3 — पुराने versions deprecated |
SSLHonorCipherOrder off | Client को best cipher choose करने दें |
SSLCompression off | CRIME attack को रोकता है |
SSLUseStapling | Server पहले से OCSP response fetch करता है |
Strict-Transport-Security | HSTS — browser हमेशा HTTPS use करना remember करते हैं |
Redirect permanent | 301 redirect HTTP → HTTPS |
Step 4: Site Enable करें और Test करें
# Debian/Ubuntu
sudo a2ensite yourdomain-ssl.conf
sudo apachectl configtest # "Syntax OK" दिखना चाहिए
sudo systemctl reload apache2
# CentOS/RHEL
sudo apachectl configtest
sudo systemctl reload httpd
अगर configtest कोई error report करता है, तो वह exact line बताता है — reload करने से पहले उसे fix करें।
Step 5: Verify करें
Browser: https://yourdomain.com पर जाएं। Padlock पर click करें → issuer के रूप में “Let’s Encrypt” verify करें।
Command line:
echo | openssl s_client -connect yourdomain.com:443 -servername yourdomain.com 2>/dev/null \
| openssl x509 -noout -subject -issuer -dates
Online: comprehensive grade के लिए SSL Labs Server Test use करें। Target: A या A+।
Apache vs Nginx: Certificate File Differences
| Apache | Nginx | |
|---|---|---|
| Certificate | SSLCertificateFile cert.pem | ssl_certificate fullchain.pem |
| Private key | SSLCertificateKeyFile privkey.pem | ssl_certificate_key privkey.pem |
| Chain | SSLCertificateChainFile chain.pem | fullchain.pem में included |
| Required files | 3 अलग-अलग files | 2 files (chain combined) |
Apache 2.4.8+ भी SSLCertificateFile में combined fullchain.pem use कर सकता है — तब आप SSLCertificateChainFile हटा सकते हैं।
Renewal
जब आपका certificate expiry के करीब हो (यहां check करें):
# Files replace करें
sudo cp new-cert.pem /etc/ssl/gethttps/cert.pem
sudo cp new-chain.pem /etc/ssl/gethttps/chain.pem
sudo cp new-privkey.pem /etc/ssl/gethttps/privkey.pem
# Reload करें (restart नहीं) — zero downtime
sudo systemctl reload apache2 # Debian/Ubuntu
sudo systemctl reload httpd # CentOS/RHEL
Full renewal guide → | Certbot से automate करें →
Troubleshooting
”AH02572: Failed to configure certificate” / key match नहीं करती
Certificate और private key एक-दूसरे से match नहीं करते। Verify करें कि वे match करते हैं:
# ये दोनों hash same होने चाहिए
openssl x509 -noout -modulus -in /etc/ssl/gethttps/cert.pem | md5sum
openssl rsa -noout -modulus -in /etc/ssl/gethttps/privkey.pem | md5sum
अगर वे different हैं, तो आप अलग-अलग GetHTTPS sessions की files use कर रहे हैं। दोनों को एक ही session से फिर से download करें।
“AH01909: server certificate does NOT include an ID”
आपका ServerName certificate के SAN field में किसी भी domain से match नहीं करता:
openssl x509 -noout -text -in /etc/ssl/gethttps/cert.pem | grep -A1 "Subject Alternative Name"
Ensure करें कि आपका Apache ServerName listed DNS names में से किसी एक से exactly match करता है।
Browser “certificate not trusted” दिखाता है
Intermediate chain missing है। Verify करें कि SSLCertificateChainFile chain.pem (intermediate) की ओर point करता है, न कि cert.pem। Chain test करें:
echo | openssl s_client -connect yourdomain.com:443 2>/dev/null | grep "Verify return code"
# "Verify return code: 0 (ok)" = अच्छा
# "Verify return code: 21 (unable to verify)" = chain incomplete
“AH00526: Syntax error on line X”
Apache config syntax error। Common reasons:
</VirtualHost>closing tag missingSSLCertificateChainFileगलत spelling- Header values के around quotes missing
- File path exist नहीं करता
HTTPS काम करता है लेकिन “Not Secure” दिखाता है
Mixed content — आपका page HTTP पर resources load करता है। DevTools → Console खोलें → http:// URLs fix करें।
FAQ
क्या मैं अलग cert + chain के बजाय fullchain.pem use कर सकता हूं?
हां, Apache 2.4.8+ पर। SSLCertificateFile /path/to/fullchain.pem use करें और SSLCertificateChainFile directive को पूरी तरह हटा दें। पुराने Apache पर, आपको अलग-अलग files चाहिए।
मेरे पास कौन सा Apache version है, यह कैसे check करें?
apachectl -v
# या
httpd -v
क्या मुझे Apache को restart करना होगा या सिर्फ reload?
Reload (systemctl reload) enough है और zero downtime देता है। Restart (systemctl restart) सभी active connections बंद कर देता है। Certificate बदलने के लिए हमेशा reload करें।
क्या Apache अलग-अलग domains के लिए अलग-अलग certificates serve कर सकता है?
हां। अलग-अलग ServerName और SSLCertificate* directives के साथ अलग-अलग <VirtualHost *:443> blocks बनाएं। Apache सही certificate choose करने के लिए SNI (Server Name Indication) use करता है।
क्या Apache ECDSA certificate support करता है?
हां। Apache 2.4+ ECDSA को RSA की तरह ही handle करता है — same directives, same file format। GetHTTPS default रूप से ECDSA P-256 generate करता है।
Apache के SSL error logs कहां हैं?
# Debian/Ubuntu
tail -f /var/log/apache2/error.log
# CentOS/RHEL
tail -f /var/log/httpd/ssl_error_log