在 Debian + LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 环境下,“加密”通常指 HTTPS(SSL/TLS)加密网站流量。下面按最常见、最推荐的方式一步步说明。
sudo apt update
sudo apt install certbot python3-certbot-nginx -y
确保你的域名(如 example.com)已解析到服务器公网 IP:
ping example.com
sudo certbot --nginx -d example.com -d www.example.com
✅ Certbot 会自动:
浏览器访问:
https://example.com
或使用:
curl -I https://example.com
Let’s Encrypt 证书 90 天有效,Debian 已自动配置 cron / systemd timer:
sudo systemctl status certbot.timer
手动测试续期:
sudo certbot renew --dry-run
假设你已有:
example.com.crtexample.com.key放到:
/etc/nginx/ssl/
server {
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /etc/nginx/ssl/example.com.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /var/www/html;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
# HTTP 跳转 HTTPS
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
重载 Nginx:
sudo nginx -t
sudo systemctl reload nginx
add_header Strict-Transport-Security "max-age=31536000" always;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
如需要我可以单独给你讲 MySQL SSL 配置
password_hash()session.cookie_secure = 1
session.cookie_httponly = 1
✅ 最推荐
apt install certbot python3-certbot-nginx
certbot --nginx -d 你的域名
✅ 自动续期
systemctl enable certbot.timer
如果你愿意,可以告诉我:
我可以 按你的实际环境给你定制一套完整配置。