nginx php服务器中,CI框架配置https报错$_SERVER[‘HTTPS’]未定义

在nginx+php的服务器中CI框架的https遇到问题详解。 ci的Config.php部分代码

function __construct()
	{
		$this->config =& get_config();
		log_message('debug', "Config Class Initialized");
		// Set the base_url automatically if none was provided
		if ($this->config['base_url'] == '')
		{
			if (isset($_SERVER['HTTP_HOST']))
			{
				$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
				$base_url .= '://'. $_SERVER['HTTP_HOST'];
				$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
			}

			else
			{
				$base_url = 'http://localhost/';
			}

			$this->set_item('base_url', $base_url);
		}
	}

$_SERVER[‘HTTPS’] 没有定义 我们需要在nginx增加配置

fastcgi_param HTTPS 'on';

我的服务器配置如下:

server {
    listen 443;
    server_name  域名;
    ssl on;
    root   目录;
    index  index.html index.htm index.php;
    ssl_certificate   /etc/nginx/cert/214403842490987.pem;
    ssl_certificate_key  /etc/nginx/cert/214403842490987.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
       location / {
                #
               # try_files $uri $uri/ /index.php/$query_string;

                if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php$1  last;
                break;
        }
        }
       location ~ \.php($|/) {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  HTTPS 'on';
            include        fastcgi_params;
        }
      error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }
}

运行 php打印 $_SERVER[‘HTTPS’] = on

即可解决问题。