Magento CDN加速Cloudflare开启https后无限重定向问题

Cloudflare是用的很多的免费CDN服务商,尤其是面向国外电商的网站。Cloudflare的CDN可以隐藏服务器IP,又提供免费的https服务,尤其吸引着一部分的人,特别是一些特殊的Magento网站,这里就不多说了,这里说的是Magento的系统怎么启用Cloudflare的免费https。 当Magento网站完成Cloudflare的接入后,Cloudflare就会给当前的域名签发ssl证书,这时候用 https://www.域名.com 就可以访问到magento的网站的。当然,这也只是能访问到,会出现非https加密连接被拒绝的错误。 嗯,到这里有感觉了,于是马上到magento后台开启https安全连接,然而到了这里才是本文提到的问题的开始,你会发现访问网站会无限重定向而over…

Cloudflare https和http都请求magento服务器80端口的情况

set ishttps "off";

if (http_x_forwarded_proto = "https") {
    set ishttps "on";
}
location ~ [^/]\.php(/|){

    try_files uri =404;
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_param HTTPSishttps;
}

上面的代码放到listen 80端口的service里面,大概意思是请求的http_x_forwarded_proto是https的,向php后端传递HTTPS=on的值。
因为magento里面是用

//_SERVER['HTTPS']this->getServer('HTTPS') == 'on'

来判断https的。
写的有点匆忙,有时间再整理一篇关于magento https无限重定向在 各种环境下的解决办法的文章出来。

2 thoughts on “Magento CDN加速Cloudflare开启https后无限重定向问题”

评论已关闭