SSL Certificates & HTTPS: Start full-site encryption with Certbot for 0 cost
📂 Phase: Phase 6 - Online Deployment (Production) 🔗 Related Chapters: Gunicorn 与 Nginx · Docker 部署全流程
1. Why must I enable HTTPS before going online?
Let’s look at the most intuitive scenario first—when a user enters a password on public Wi‑Fi:
In addition to preventing leakage, HTTPS has five irreplaceable advantages in the modern web ecosystem:
- Prevent ISP/public Wi‑Fi traffic hijacking and avoid pages being filled with malicious advertisements.
- Prevent middlemen from tampering with your HTML/CSS/JS (such as adding phishing links to buttons).
- SEO hard threshold: Google and Baidu clearly prioritize HTTPS sites, and pure HTTP sites will even be demoted.
- Browser Trust Mark: Chrome/Firefox will mark HTTP sites as “unsafe”, which directly affects the conversion rate.
- Prerequisites for turning on HTTP/2: HTTP/2 can increase speed by 30%–50%, but all major browsers require HTTPS.
2. Get a 90-day automatic renewal certificate at zero cost
Many free certificates in China either change once a year, only support a single domain name, or come from small organizations. The world’s most reliable free solution is Let’s Encrypt + Certbot.
2.1 Two roles
- Let’s Encrypt: A non-profit certificate authority, endorsed by Google, Microsoft, Mozilla and other major manufacturers, trusted by all major browsers, the certificate is permanently free, supports multiple domain names and wildcards, and is valid for 90 days.
- Certbot: The official automation tool helps you "apply → configure web server → set up automatic renewal", the whole process takes less than 5 minutes.
2.2 Install Certbot
Certbot is very well adapted to all mainstream systems and can be installed directly with the package manager:
2.3 Recommendation for novices: Nginx fully automatic configuration
If you have already configured an HTTP site with Nginx (such as the Gunicorn + Nginx you learned before), you can do it all with just one command:
Four questions need to be answered during the interaction:
- Email address: Used to receive emergency notifications of certificate expiration (only 2‑3 emails will be received in a year).
- Agree to the Terms of Service: Required
A(Agree)。 - Whether to share the mailbox with EFF:
YorNFeel free (EFF is a nonprofit that promotes online privacy). - Whether to automatically jump to HTTPS: Strongly recommended to select
2(Redirect), forces all HTTP requests to be 301 permanently redirected to HTTPS to avoid mixed content problems.
When finished you will seeCongratulations!tips. Refresh the browser and the website will now be securely locked!
2.4 Advanced version: just get the certificate and match it yourself
If you don't want Certbot to change the existing Nginx configuration, you can also just apply for a certificate and then configure it manually. Choose one of the two according to your verification method:
After the application is successful, the certificate will be saved in/etc/letsencrypt/live/你的域名/Next, the path will remain unchanged after renewal. You need to pay attention to two files:
fullchain.pem: Certificate chain (sent to browser).privkey.pem:Private key (Never disclose it!).
3. Advanced security Nginx HTTPS configuration
Certbot's auto-generated configuration is already available, but some enhancements are needed if you want an SSL Labs A+ rating (a production-grade security standard). Below is a set of complete configuration templates that have been verified and compatible with mainstream browsers (Chrome 60+, Firefox 55+, Safari 12+):
After the configuration is completed, verify first and then reload to avoid service interruption:
4. 90-day automatic renewal: once and for all
Let’s Encrypt certificates are only valid for 90 days to reduce the risk period if the private key is compromised. Certbot comes with renewal capabilities, we just need to ensure that the scheduled tasks work properly.
4.1 Test the renewal process first
Before formal setup, it is strongly recommended to do a test run:
SeeCongratulations, all renewals succeededIt means there is no problem with the configuration.
4.2 Configure scheduled renewal
Method 1: systemd timer (Ubuntu 18.04+ / CentOS 8+ recommended)
Modern Linux distributions usually come with systemd timer after installing Certbot, just check the status:
The Timer will be randomly offset for a period of time every morning to perform renewal. After the renewal is successful, Certbot will automatically reload Nginx.
Method 2: crontab (compatible with old systems)
If you don’t have systemd, you can use the root user’s crontab:
5. Check your HTTPS security level
After the deployment is completed, it is recommended to use professional tools to conduct a comprehensive inspection.
Online detection (preferred)
- SSL Labs (the world’s most authoritative): https://www.ssllabs.com/ssltest/
- MySSL (faster in China, Chinese interface): https://myssl.com/
Local quick check
6. Pitfall guide: Common HTTPS issues
6.1 Mixed Content (mixed HTTP / HTTPS) warning
⚠️ Symptom: The browser address bar displays "little green lock with an exclamation mark", and the console reports
Mixed Contentmistake.
Reason: The page quotedhttp://The opening image, CSS, JS and other resources.
Solution: Change all resource links tohttps://or use relative protocol//(Automatically follows the current protocol).
6.2 Certificate renewal failed
⚠️ Symptom: Renewal Times
Failed authorization procedure。
Most likely because the verification path of Let’s Encrypt is inaccessible, please check in this order:
- Is it retained in the Nginx configuration?
.well-known/acme-challenge/location block. - Whether the firewall has allowed port 80** (renewal must be verified using HTTP).
- Is the domain name resolution normal (
ping 你的域名See if it can be connected).
7. Summary
Full-site HTTPS is already a bottom-line requirement for production projects, and it can be implemented within 10 minutes at zero cost using Let’s Encrypt + Certbot.
Quick review of the deployment process:
- Install Certbot and the corresponding Nginx plug-in
- Execution
certbot --nginx -d 你的域名Apply and configure with one click - (Optional) Replace with advanced security Nginx configuration and sprint SSL Labs A+
- Confirm that automatic renewal (systemd timer or crontab) has taken effect
- Use SSL Labs or MySSL to check the security level
💡 Last reminder for production level
- Be sure to enable HSTS to prevent users from accidentally visiting HTTP sites.
- Review your security score with SSL Labs every month.
- Never place
privkey.pemCommit to a version control system (like Git)!
🔗 Extended reading
- Let’s Encrypt 官方文档
- Certbot 官方文档
- Mozilla SSL Configuration Generator (generate security configuration with one click)
- SSL Labs SSL Test (authoritative detection)

