在Debian上为Laravel设置HTTPS,您需要完成以下步骤:
sudo apt update
sudo apt install certbot python3-certbot-nginx
yourdomain.com
替换为您的实际域名。运行以下命令:sudo certbot --nginx -d yourdomain.com
Certbot将自动配置Nginx以使用HTTPS,并将SSL证书安装在适当的位置。
/etc/nginx/sites-available/
目录中。打开您的站点配置文件,然后添加或修改以下内容: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;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers on;
root /var/www/yourdomain.com/public;
index index.php index.html index.htm;
location /
{
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$
{
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht
{
deny all;
}
}
确保将yourdomain.com
替换为您的实际域名,并根据需要调整其他设置。
sudo systemctl restart nginx
.env
文件中的APP_URL
设置为HTTPS:APP_URL=https://yourdomain.com
find /path/to/your/laravel/project -type f -exec sed -i 's/http:\/\/yourdomain.com/http:\/\/yourdomain.com/g' {} \;
将/path/to/your/laravel/project
替换为您的Laravel项目的实际路径,并将yourdomain.com
替换为您的实际域名。
完成这些步骤后,您的Debian服务器上的Laravel应用程序应该已经通过HTTPS提供服务。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: Debian邮件服务器虚拟主机配置方法