简体   繁体   中英

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.

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. I am wondering how to do this without writing setBaseUrl everywhere.

(We are using 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 ? Shouldn't it be using app.url as a base 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:

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

(same as your proxy_pass upstream block)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM