在Ubuntu系統中部署ThinkPHP應用的SSL證書,通常需要以下幾個步驟:
獲取SSL證書:
安裝Certbot:
sudo apt update
sudo apt install certbot python3-certbot-nginx
配置Nginx:
example.com
。/etc/nginx/sites-available/example.com
。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/example.com;
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;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
啟用SSL證書:
sudo certbot --nginx -d example.com -d www.example.com
重啟Nginx:
sudo systemctl restart nginx
配置ThinkPHP應用:
config/app.php
中,確保URL生成使用HTTPS:'url_domain_deploy' => true,
'url_http_port' => '443',
'url_https_port' => '443',
測試SSL證書:
https://example.com
,確保SSL證書正確安裝并且頁面可以正常訪問。通過以上步驟,你應該能夠在Ubuntu系統中成功部署ThinkPHP應用的SSL證書。如果有任何問題,請檢查Nginx配置文件和SSL證書路徑是否正確。