首页 > 解决方案 > bundle.js 未在静态 html 文件中成功加载,但请参阅

问题描述

我在使用StaticFiles的asp.net核心Web项目的wwwroot中有一个静态index.html:

<html>
    ...
    <body>
    ...
    <script src="~/scripts/bundle.js"></script>
    </body>    
</html>

Web 应用程序发布后。bundle.js 无法成功加载,在 Chrome 中按 F12 后发现浏览器试图通过 url 加载 js: https ://127.0.0.1:5001/~/scripts/bundle.js

请提供线索。谢谢!顺便说一句,Web 应用程序在本地运行流畅,没有此类错误。

标签: htmlasp.net-corenginxweb

解决方案


这实际上是一个 Nginx 配置问题。https://www.***.com/subpath1/test.html. nginx 将 subpath1 代理到托管 test.html 的本地端口 5588。在 test.html<script src="bundle.js">中没有 https://www.***.com/subpath1/bundle.js按预期引用,但https://www.***.com/bundle.js 因此更新 test.html src 属性src="subpath1/bundle.js"解决了问题。谢谢大家~


推荐阅读