線上的一個網站運行了一段時間,應領導要求,將其訪問方式更改為https加密方式。
更改為https后,網站訪問正常,但網站注冊功能不能正常使用了!
經過排查,是nginx配置里結合php部分漏洞了一個參數(fastcgi_param HTTPS )導致,添加上這個參數后,問題迎刃而解!
nginx支持https的配置時,需要在php區域配置中添加FastCGI服務,否則https不支持php文件。
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”?
這是個 fastcgi 的配置問題!
解決方法:
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;
}
解釋:
很多人認為使用 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 之后的版本