[英]Laravel 4: setting correct scheme and domain for pagination and form
This is probably an oversight on my part, but I am wondering what's the correct way to set the default pagenate base url.这可能是我的疏忽,但我想知道设置默认 pagenate 基本 url 的正确方法是什么。
Our domain is on https://domain.com
and we have set config app.url
as such, but pagination still appear to use http://domain.com
(note the scheme is http
instead of https
) when generating url in view.我们的域在https://domain.com
,我们已经设置了 config app.url
,但是在视图中生成 url 时,分页似乎仍然使用http://domain.com
(注意该方案是http
而不是https
) . I am wondering how to do this without writing setBaseUrl
everywhere.我想知道如何在不到处写setBaseUrl
情况下做到这一点。
(We are using Laravel 4.1) (我们使用的是 Laravel 4.1)
Update : we got the same problem with Form::open
as well, where is the setting that make Laravel realize we want url with https
instead of http
?更新:我们也遇到了与Form::open
相同的问题,让 Laravel 意识到我们想要使用https
而不是http
url 的设置在哪里? Shouldn't it be using app.url
as a base url?不应该使用app.url
作为基本 url 吗?
Figure out the answer myself:自己找出答案:
Since our server is behind a reverse proxy (nginx), while content is served as HTTPS, the proxying is done with HTTP, so we should set following to nginx config:由于我们的服务器在反向代理(nginx)之后,而内容作为 HTTPS 提供,代理是通过 HTTP 完成的,因此我们应该在 nginx 配置中设置以下内容:
proxy_set_header X-Forwarded-Proto $scheme; //or just `https`
(same as your proxy_pass upstream
block) (与您的proxy_pass upstream
块相同)
Then we can use Trusting Proxies feature as such:然后我们可以使用信任代理功能:
$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);
}
(This can be added to bootstrap/start.php
. Laravel use Symfony Request library, which is why we linked to their document, as this feature is not documented in Laravel docs) (这可以添加到bootstrap/start.php
。Laravel 使用 Symfony 请求库,这就是我们链接到他们的文档的原因,因为该功能未在 Laravel 文档中记录)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.