在Debian系统中部署Laravel应用程序的SSL证书,通常涉及以下几个步骤:
获取SSL证书:
安装Certbot:
sudo apt update
sudo apt install certbot python3-certbot-nginx
配置Nginx:
编辑Nginx服务器块文件,通常位于/etc/nginx/sites-available/目录下。
确保你的Laravel应用程序的server块配置如下:
server {
listen 80;
server_name example.com www.example.com;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
root /var/www/html/laravel;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据你的PHP版本调整
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
确保将example.com替换为你的域名,并将/var/www/html/laravel替换为你的Laravel应用程序的实际路径。
测试Nginx配置:
sudo nginx -t
重新加载Nginx:
sudo systemctl reload nginx
设置自动续订:
sudo certbot renew --dry-run
配置防火墙:
sudo ufw allow 'Nginx Full'
完成以上步骤后,你的Laravel应用程序应该已经成功部署了SSL证书,并且可以通过HTTPS访问。