在CentOS上配置Laravel项目的SSL证书,通常需要以下几个步骤:
获取SSL证书:
安装Certbot:
sudo yum install epel-release
sudo yum install certbot python2-certbot-apache
获取并安装SSL证书:
example.com:sudo certbot --apache -d example.com -d www.example.com
配置Laravel项目:
.env文件中的APP_URL:APP_URL=https://example.com
php artisan migrate
php artisan config:cache
配置Nginx(如果使用Nginx):
/etc/nginx/conf.d/或/etc/nginx/sites-available/目录下),添加以下内容: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 /path/to/your/laravel/project;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-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;
}
}
sudo systemctl reload nginx
测试配置:
通过以上步骤,你应该能够在CentOS上成功配置Laravel项目的SSL证书。