转自https://www.wdlinux.cn/bbs/viewthread.php?tid=58673&highlight=https
NGINX站点conf配置文件中,在443的那一段里加上:
location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
proxy_set_header X-Forwarded-Proto https;//header头信息增加这一行
}
location ~ /\.ht {
deny all;
}
location / {
try_files $uri @apache;
}
location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
proxy_set_header X-Forwarded-Proto https;//header头信息增加这一行
}
php中通过$_SERVER['HTTP_X_FORWARDED_PROTO']判断
//PHP判断当前协议是否为HTTPS
if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
return true;
} elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
return true;
} elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
return true;
}else{
return false;
}