Laravel 4:为分页和表单设置正确的模式和域


Laravel 4: setting correct scheme and domain for pagination and form

这可能是我的疏忽,但我想知道设置默认页面基url的正确方法是什么。

我们的域名在https://domain.com上,我们已经设置了配置app.url,但是在生成url时,分页仍然使用http://domain.com(注意方案是http而不是https)。我想知道如何做到这一点,而不写setBaseUrl无处不在。

(我们正在使用Laravel 4.1)

更新:我们得到了同样的问题与Form::open,在哪里设置,使Laravel意识到我们想要url与https而不是http ?它不应该使用app.url作为基础url吗?

自己找出答案:

由于我们的服务器是反向代理(nginx),而内容是作为HTTPS服务,代理是通过HTTP完成的,所以我们应该设置以下nginx配置:

proxy_set_header X-Forwarded-Proto  $scheme; //or just `https`

(和你的proxy_pass upstream块一样)

那么我们可以这样使用可信代理特性:

$proxies = Config::get('app.trusted_proxies');
// trust any balancer
if ($proxies === '*')
{
    $proxies = array( Request::getClientIp() );
}
// else trust an array of IPs
if ($proxies && is_array($proxies))
{
    Request::setTrustedProxies($proxies);
}

(这可以添加到bootstrap/start.php。Laravel使用Symfony请求库,这就是为什么我们链接到他们的文档,因为这个特性没有在Laravel文档中记录)