如何通过https在Laravel 5中提供静态内容? [英] How to serve static content in Laravel 5 over https?

查看:79
本文介绍了如何通过https在Laravel 5中提供静态内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间试图解决这个问题,但到目前为止还没有任何运气.我的应用由于内容混合错误而无法加载CSS(" https://example.com/上的页面"已通过HTTPS加载,但请求了不安全的样式表" http://example.com/assets /css/magazine.min.css '.此请求已被阻止;该内容必须通过HTTPS提供).我知道可以通过将真实值传递给资产函数来加载资产,但这意味着我将必须转到所有资产调用并进行更改.是否可以配置站点范围的设置,以便在生产环境中使用https,在本地环境中使用http?

I've spent a ton of time trying to fix this but haven't had any luck so far. My app isn't loading css because of a mixed content error (The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://example.com/assets/css/magazine.min.css'. This request has been blocked; the content must be served over HTTPS). I know that I can load the assets by passing in true to the asset function but that would mean I would have to go to all the asset calls and change them. Is there a site wide setting I can configure so that it does https in production and http in local?

谢谢

推荐答案

您可以创建类似于ForceHttps中间件的东西,然后为其内部环境创建条件,如下所示:

You can create something like ForceHttps middleware and than create condition for environment inside of it, like this:

public function handle($request, Closure $next)
{
    if (!\App::environment('local')) {
        \URL::forceSchema('https');
    }

    return $next($request);
}

如果需要,可以将其添加到某个路由组或全局路由.

Than add it to some route group or globally if you want.

注意:我建议在您的Web服务器上解决此问题,而不是在Laravel中解决

这篇关于如何通过https在Laravel 5中提供静态内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆