发布于2026-08-21 阅读(0)
扫一扫,手机访问
在Debian系统上,要为LNMP(即Linux、Nginx、MySQL、PHP的组合)配置SSL,让其支持HTTPS,这需要经历几个特定的步骤。接下来,我将为你提供一个基础的指南,帮助你完成SSL证书的设置,并对Nginx进行相应配置,以实现HTTPS的正常使用。

Certbot是一个自动化的工具,用于获取和续订Let’s Encrypt SSL证书。你可以使用以下命令安装Certbot:
sudo apt update
sudo apt install certbot python3-certbot-nginx使用Certbot获取SSL证书。运行以下命令并按照提示操作:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.comCertbot会自动配置Nginx以使用SSL证书,并创建一个指向你的网站的符号链接。
Certbot会自动检测你的Nginx配置文件是否存在语法错误。要是有错误,它会提示你去修复。当然,你也能手动测试Nginx配置文件的语法哦:
sudo nginx -t如果没有错误,重新加载Nginx以应用更改:
sudo systemctl reload nginxCertbot会自动设置一个cron作业来定期续订你的SSL证书。你可以手动测试续订过程以确保一切正常:
sudo certbot renew --dry-run如果一切正常,Certbot会在证书到期前30天自动续订证书。
确保你的防火墙允许HTTPS流量。如果你使用的是ufw,可以运行以下命令:
sudo ufw allow 'Nginx Full'HSTS(HTTP Strict Transport Security):强制浏览器始终通过HTTPS访问你的网站。
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;OCSP Stapling:提高SSL握手速度和安全性。
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;将上述配置添加到你的Nginx服务器块中,以启用这些可选功能。
以下是一个基本的Nginx服务器块配置示例,包括SSL设置:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name yourdomain.com www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
root /var/www/html;
index index.php index.html index.htm;
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location / {
try_files $uri $uri/ =404;
}
}请根据你的实际情况调整配置。
完成这些步骤后,你的Debian服务器上的LNMP环境应该已经成功配置了SSL。
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
4
5
6
7
8
9