线上的一个网站运行了一段时间,应领导要求,将其访问方式更改成https加密方式。
更改成https后,网站访问正常,但网站注册功能不能正常使用了!php
通过排查,是nginx配置里结合php部分漏洞了一个参数(fastcgi_param HTTPS )致使,添加上这个参数后,问题迎刃而解!
nginx支持https的配置时,须要在php区域配置中添加FastCGI服务,不然https不支持php文件。nginx
location ~ \.php$ {
root /var/www/vhosts/fff/main;
fastcgi_pass 127.0.0.1:9000;
fastcgi_read_timeout 30;
fastcgi_index fff.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
fastcgi_param HTTPS on; 【或者fastcgi_param HTTPS $https if_not_empty; 】
}
} 服务器
*******************************************************************************************网站
如何开启 Nginx 的 SSL 或者 HTTPS呢?加密
你们有没有试过使用HTTPS登录 phpmyadmin 的时候会自动返回“The plain HTTP request was sent to HTTPS port”?spa
这是个 fastcgi 的配置问题!unix
解决方法:ip
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_index index.php;
include fcgi.conf;
}字符串
解释:io
不少人认为使用 fastcgi_param HTTPS on;,这样是没错啦,不过强迫使用这个参数,可能不太有效!
最好的答案是上面的配置(参考下面 nginx 官方的连接)
fastcgi_param HTTPS $https if_not_empty;
有 https 协议时才自动使用 https on,不然忽略这个参数。
内嵌的变量:
$https – 若是连接是 SSL 就返回 “ON”,不然返回空字符串。
if_not_empty; – 当参数有值时才传递到服务器
注意:这个 if_not_empty 额外参数只适合 Nginx 1.1.11 以后的版本