当我配置完成SSL证书后,访问线上的TP3.2.3框架确一直在下载index.php文件,百思不得其解,好烦!!
我的nginx.conf中结尾有这样一句话 : include /etc/nginx/conf.d/*.conf;
于是我创建了以 .conf结尾到的 local.conf文件, 同在nginx.conf写配置是一样的.
下面贴出我的配置方法:
server {
listen 80;
server_name www.*.com;
#charset koi8-r;
#rewrite ^(.*) https://$server_name$1 permanent; # 红色字体的配置都是强制跳转https,二选一即可
#access_log logs/host.access.log main;
return 301 https://$host$request_uri;
location / {
root * #项目根目录
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last; #注(目的是将/后面的路径前加上index.php)
}
}
# HTTPS server
#
server {
listen 443 ssl;
server_name www.*.com;
ssl on;
root html;
index index.html index.htm;
ssl_certificate /etc/nginx/cert/*.crt; #SSL证书
ssl_certificate_key /etc/nginx/cert/*.key;
# ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root * ; #项目根目录
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last; #注(目的是将/后面的路径前加上index.php)
}
location ~ \.php(.*)$ {
root * ; #项目根目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param HTTPS on;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
}
出现下载index.php问题的原因可能是 nginx没有解析php-fpm路径
我就是通过在配置SSL证书的server{}代码块中添加ocation ~ \.php(.*)$ {}代码块 让nginx解析php-fpm路径才成功解决!!
心累啊.....
以上代码解决方案属个人自己见解,请大佬轻喷,欢迎指正!!