Laravel资产URL忽略https [英] Laravel asset URL ignoring https

查看:514
本文介绍了Laravel资产URL忽略https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的模板中使用以下代码加载我的CSS文件:

I am using the following code in my template to load in my CSS file:

<link rel="stylesheet" href="{!! URL::asset('css/app.css') !!}">

如果我在本地机器上通过https查看页面,那么指向app.css文件的链接是还有https,但是在我的实时服务器上这没有发生。如果您通过https 查看实时网站并查看源代码,您可以看到指向CSS文件的链接仍然超过正常的http,所以不加载。有谁知道为什么会发生这种情况?

If I view the page over https on my local machine then the link to the app.css file is also https, however on my live server this isn't happening. If you view the live site over https and view the source you can see that the link to the CSS file is still over normal http and so doesn't load. Does anyone know why this is happening?

推荐答案

当您的用户通过HTTPS访问时,您的CloudFlare配置会将这些请求传递给您服务器使用HTTP。您有两种选择:

While your users are accessing via HTTPS, your CloudFlare configuration is passing those requests onto your server using HTTP. You have two options:


  1. 启用CloudFlare的完整或严格SSL。 https://blog.cloudflare.com/origin-server- connection-security-with-universal-ssl /

设置您的网络服务器以查看 X-Forwarded-Proto 标题并告诉PHP当标题的值为 https 时,它将通过HTTPS访问。如何做到这一点取决于你的网络服务器。例如,在nginx中,我为亚马逊的ELB(发送相同的标题)执行此操作:

Set up your webserver to see the X-Forwarded-Proto header and tell PHP it's being accessed via HTTPS when that header's value is https. How to do this depends a bit on your webserver. In nginx, for example, I do this for Amazon's ELB (which sends the same headers):

map $http_x_forwarded_proto $is_https {
    default off;
    https on;
}

然后在我的FastCGI params文件中:

and then this in my FastCGI params file:

fastcgi_param  HTTPS              $is_https if_not_empty;

在Apache中,我认为如果安装了mod_setenvif,你可以这样做:

In Apache, I think you can do this if mod_setenvif is installed:

SetEnvIf x-forwarded-proto https HTTPS=on

这篇关于Laravel资产URL忽略https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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