π SSL/TLS Configuration β Apache HTTPS Guide
Secure your site with SSL/TLS to encrypt traffic, build trust, and boost SEO! π
π What is SSL/TLS?β
- SSL (Secure Sockets Layer) and TLS (Transport Layer Security) are protocols that encrypt web traffic.
- Modern servers always use TLS (even when we say "SSL"). π
- Apache uses
mod_ssl
(backed by OpenSSL) to manage TLS encryption.
β Why Enable SSL/TLS?β
- π Encrypts all user data (forms, passwords, cookies)
- π‘οΈ Prevents eavesdropping & man-in-the-middle attacks
- π Displays the HTTPS padlock in browsers (trust signal)
- π Improves SEO and meets modern web standards
βοΈ Enable SSL Module in Apacheβ
sudo a2enmod ssl
sudo systemctl restart apache2
This loads mod_ssl
, allowing Apache to listen on port 443.
π HTTPS Virtual Host Example (*:443
)β
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/example
SSLEngine on
SSLCertificateFile /etc/ssl/certs/example.crt
SSLCertificateKeyFile /etc/ssl/private/example.key
ErrorLog ${APACHE_LOG_DIR}/ssl-error.log
CustomLog ${APACHE_LOG_DIR}/ssl-access.log combined
</VirtualHost>
π Redirect HTTP β HTTPS (Recommended)β
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
Ensures all traffic is encryptedβno HTTP version leaks.
π Get a Free SSL Certificate (Letβs Encrypt + Certbot)β
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com
Certbot automatically configures HTTPS and renews certificates every 60 days! π
π§ͺ Strong TLS Settings (Hardening)β
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite HIGH:!aNULL:!MD5
SSLHonorCipherOrder on
SSLCompression off
SSLSessionTickets off
- Disables old protocols (SSLv2/3, TLS1.0/1.1)
- Enables secure ciphers only (no null or MD5)
- Prioritizes serverβs cipher choice
- Turns off compression & session tickets (CRIME prevention)
π Add HSTS Header β Enforce HTTPS Foreverβ
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
- Enables HSTS, forcing browsers to always use HTTPS for 1 year
- Supports subdomains and preload lists
Remember: Only add this in SSL vhost, not HTTP vhost!
π οΈ Disabling TLSv1.0/1.1 Only (if needed)β
SSLProtocol +TLSv1.2 +TLSv1.3
Use nmap --script ssl-enum-ciphers -p 443 example.com
to test supported protocols.
π Summary Tableβ
Directive | Purpose |
---|---|
SSLEngine on | Enables HTTPS for the vhost |
SSLCertificateFile , Key | Certificate and private key file paths |
SSLProtocol | Specifies which TLS protocols to allow |
SSLCipherSuite | Defines the allowed cipher algorithms |
SSLHonorCipherOrder | Enforces server-side cipher preference |
SSLCompression off | Disables compression (prevents CRIME) |
SSLSessionTickets off | Disables session tickets (PFS protection) |
Strict-Transport-Security | Enables HSTS for long-term HTTPS enforcement |
π§ Best Practices Tipsβ
- π Always redirect HTTP to HTTPS
- π€ Use automated Certbot for renewals
- π§Ή Remove weak protocols (TLS < 1.2)
- π Set HSTS headers only in secure contexts
- π Validate with SSL Labs (aim for A+ grade)
You're now equipped with a secure, modern Apache TLS setup! π― Ready to tackle security.md
or performance-tuning.md
next?