【问题标题】:Can not get css and js files in the server that use SSL无法在使用 SSL 的服务器中获取 css 和 js 文件
【发布时间】:2015-06-26 17:32:18
【问题描述】:

我在 codeigniter 中实现了一个网站,最近我将它上传到了具有 SSL 的生产服务器。

问题是,如果我使用“http”输入,一切正常。如果我使用 "https" 输入,则找不到所有 css 和 js。错误是:

Mixed Content: The page at 'https://www.xxxx.com/' was loaded over a secure connection, but contains a form which targets an insecure endpoint 'http://www.xxxx.com/secure/validate_credentials'. This endpoint should be made available over a secure connection.

Mixed Content: The page at 'https://www.xxxx.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://www.xxxx.com/assets/font-awesome/css/font-awesome.css'. This request has been blocked; the content must be served over HTTPS.

我已经在 codeigniter 中编辑了 config.php

例如$config['base_url'] = "https://www.xxxx.com/"

但还是会发生,如何调试和修复?感谢您的帮助

【问题讨论】:

  • 你试过这样的$config['base_url'] = "//www.xxxx.com/"
  • 谢谢我去试试
  • 它可以获取 js/css ,但是当我转到每个页面时,它都会重定向到xxxx.com/www.xxxx.com

标签: javascript php css codeigniter ssl


【解决方案1】:

就像maque 说你有你的错误信息中的一切

但对于css、js和图片等资源,建议使用base_url()而不是site_url

你可以升级到 Codeigniter 3.0 it is still in develop in the time of writing this answer,但它在这个阶段非常可靠,它有更好的 base_url()site_url() 版本,因为你现在可以像这样在参数中添加协议

site_url("assets/js/jquery.min.js", "https")

【讨论】:

    【解决方案2】:

    您的错误消息中包含所有内容:

    This request has been blocked; the content must be served over HTTPS.
    

    看起来您的 html 中有指向“http”的静态链接。所以不要像这样直接在你的 html 中使用协议:

    http://www.xxxx.com/assets/font-awesome/css/font-awesome.css
    

    把它改成这样:

    assets/font-awesome/css/font-awesome.css
    

    另外请记住,如果您尝试使用来自未配置为使用 https 提供内容的其他域的 JS 或 CSS,您将遇到此问题。

    【讨论】:

    • 感谢您的回答,但在我的 html 中,我包含了这样的 css / js,site_url("assets/js/jquery.min.js");那么如何解决呢?
    • 这意味着不能修改 site_url 来返回 https ?,因为我在很多文件中都使用过它,如果我能覆盖那个函数就好了,谢谢
    • 您是否尝试将基本 url 设置为空(如果可以):$config['base_url'] = '' ?
    猜你喜欢
    • 1970-01-01
    • 2020-01-23
    • 2018-05-02
    • 2021-04-09
    • 2013-06-30
    • 1970-01-01
    • 2012-05-27
    • 1970-01-01
    • 2016-11-11
    相关资源
    最近更新 更多