在Debian系統上為Laravel應用程序提供SSL證書,通常需要以下幾個步驟:
獲取SSL證書:
安裝Certbot:
sudo apt update
sudo apt install certbot python3-certbot-nginx
獲取并安裝SSL證書:
example.com
:sudo certbot --nginx -d example.com -d www.example.com
配置Laravel:
.env
文件中設置了正確的SSL相關配置:FORCE_SSL=true
驗證SSL證書:
https://example.com
,確保SSL證書正確安裝并且網站可以通過HTTPS訪問。使用Certbot獲取SSL證書:
sudo certbot --nginx -d example.com -d www.example.com
如果你還沒有安裝Certbot,可以使用以下命令:
sudo apt update
sudo apt install certbot python3-certbot-nginx
Certbot會自動修改你的Nginx配置文件(通常位于/etc/nginx/sites-available/example.com
),添加SSL相關的配置。確保配置文件中包含以下內容:
server {
listen 80;
server_name example.com www.example.com;
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;
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; # 根據你的PHP版本調整
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
確保Laravel應用程序的.env
文件中設置了以下環境變量:
FORCE_SSL=true
打開瀏覽器并訪問https://example.com
,確保SSL證書正確安裝并且網站可以通過HTTPS訪問。
通過以上步驟,你可以在Debian系統上為Laravel應用程序成功配置SSL證書。