在Debian系统上配置LNMP(Linux, Nginx, MySQL, PHP)以使用SSL证书,可以按照以下步骤进行:
1. 安装Nginx
如果你还没有安装Nginx,可以使用以下命令进行安装:
sudo apt update
sudo apt install nginx
2. 获取SSL证书
你可以从Let’s Encrypt免费获取SSL证书。使用Certbot工具可以简化这个过程。
安装Certbot
sudo apt install certbot python3-certbot-nginx
获取证书
运行Certbot来获取证书:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
按照提示完成证书的获取和配置。
3. 配置Nginx
Certbot会自动修改你的Nginx配置文件以启用SSL。通常,配置文件位于/etc/nginx/sites-available/yourdomain.com。
你可以手动编辑这个文件来进一步自定义配置。以下是一个基本的SSL配置示例:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
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;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据你的PHP版本调整
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
4. 重启Nginx
保存配置文件后,重启Nginx以应用更改:
sudo systemctl restart nginx
5. 验证SSL配置
你可以使用以下命令来验证你的SSL配置是否正确:
sudo nginx -t
6. 设置自动续期
Certbot会自动设置一个cron任务来定期续期证书。你可以手动测试续期过程:
sudo certbot renew --dry-run
如果一切正常,Certbot会自动续期证书并更新Nginx配置。
通过以上步骤,你就可以在Debian系统上成功配置LNMP以使用SSL证书了。
以上就是关于“Debian LNMP如何配置SSL”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm