【发布时间】:2013-01-04 16:35:43
【问题描述】:
我们正在构建一个新服务器: Pound -> Varnish -> Apache -> CentOS。
由于 Varnish 在 SSL 中不起作用,我们将 Pound 中的“X-Forwarded-Proto”设置为“https”,如果我们在 https 中,我们正在检测这种方式。
当我们直接访问像 https://example.com 这样的 URL 时,它可以工作,但当我们使用“htaccess”或“PHP”从“http”重定向到“https”时,它就不行了。似乎 X-Forwarded-Proto 没有通过重定向转发。所以我们陷入了无限重定向循环。
我们找到了一种使用 javascript 执行重定向的方法,但我们更希望有一个服务器端解决方案。
所以我们想知道 apache、磅、清漆等是否有更改的设置?
我们尝试了很多解决方案,例如:
////////////////
// htaccess
////////////////////
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://example.com [L,R]
///////////////////
// php
//////////////////
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
$_SERVER['HTTPS']='on';
}
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'){
header('Location: '. 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}
Our pound config look like:
//////////////////
// pound
///////////////
ListenHTTPS
Address 0.0.0.0 # all interfaces
Port 443
AddHeader "X-Forwarded-Proto: https"
HeadRemove "X-Forwarded-Proto"
HeadRemove "X-Forwarded-For"
Cert "/path/to/certificate.pem
Service
BackEnd
Address 10.0.0.1
Port 80
Priority 1
End
End
End
感谢大家的帮助,我们在这个问题上花了很多时间!
【问题讨论】:
-
我们终于解决了我们的问题。我们必须将“RewriteLocation 0”放在“ListenHTTP”中,并在配置中修复一个域名 issu。
-
请添加您的评论作为您的答案
-
谢谢你。我知道这是旧的,但这应该标记为已解决。多么令人沮丧的问题。
标签: apache https centos varnish