在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证书路径是否正确。