Nginx+php-fpm SSL不输出$_SERVER['HTTPS']的解决办法

最近在API接口上使用了SSL,访问签名用到了Url,后面发现服务器端与客户端签名一直对不上,PHP框架使用了Yii2,追朔源码,它是这么判断是否https连接的:

    public function getIsSecureConnection()
    {
        return isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1)
            || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0;
    }


OK,print_r($_SERVER),发现没有HTTPS,也没有HTTP_X_FORWARDED_PROTO。度娘一番,我使用的是nginx+php-fpm,在nginx配置上要加下以下这行:

		fastcgi_pass 127.0.0.1:9001;
		fastcgi_index index.php;
		include fcgi.conf;
		fastcgi_param  HTTPS on;


问题解决,打印$_SERVER['HTTPS']=on了!

你可能感兴趣的:(PHP)