今天在配置Nginx+SSL的時候出現如題的錯誤,后來與度娘一番云雨之后找到一個解決方法,挺有用,隨手轉之。
一般在vhost的配置中會有php解析的一段,如:
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;
這樣是沒錯,不過強迫使用這個參數,不太有效!
最好的答案就是 fastcgi_param HTTPS $https if_not_empty; (參考下面 nginx 官方的鏈接),有 https 協議時才自動使用 https on,否則忽略 fastcgi_param HTTPS 這個參數。
內嵌的變量:
$https – 如果鏈接是 SSL 就返回 “ON”,否則返回空字符串。
if_not_empty; – 當參數有值時才傳遞到服務器
注意:這個方法只適合 Nginx 1.1.11 之后的版本