我得到的错误如下:
10:24:45.375 localhost/:1 Refused to execute script from 'https://localhost/runtime.a66f828dca56eeb90e02.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
10:24:45.390 localhost/:1 Refused to execute script from 'https://localhost/polyfills.2f4a59095805af02bd79.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
10:24:45.391 localhost/:1 Refused to execute script from 'https://localhost/main.4946ee69e21757a0ea38.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
10:24:50.815 localhost/:1 Refused to apply style from 'https://localhost/styles.34c57ab7888ec1573f9c.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.在NGINX中将X-Content-Type-Options设置为nosniff之后。我正在构建Angular (版本6.0.3),比如
"ng build --prod --configuration=production --subresource-integrity"输出的index.html如下所示:
...
<body>
<app-root></app-root>
<script type="text/javascript" src="runtime.a66f828dca56eeb90e02.js" integrity="sha384-v4rB9z5qXuO6U644SALSrNM0l0wvQcniOlRg9Lk3fA3ljnzuAPpETTdOPFjvxVhc" crossorigin="anonymous"></script><script type="text/javascript" src="polyfills.2f4a59095805af02bd79.js" integrity="sha384-ducWBZzn39ArKnKYY70ngb3N7WZhfaMAfPG/AMC1XZcbUcvz0GmT3ymoBXA7KrUt" crossorigin="anonymous"></script><script type="text/javascript" src="main.d28db731850ff9163bb0.js" integrity="sha384-ewBSByvIwZ3px9WtXD5S4GxV8AtRmjlqDY4RS81hPo3D6j1NU3EcB/Hd7zw7KA+4" crossorigin="anonymous"></script></body>为什么指定的类型是text/javascript而不是application/javascript?是这种不匹配导致了错误还是其他原因?那么为什么Chrome报告because its MIME type ('text/plain') is not executable,检测到的MIME类型与指定的完全不同?
顺便说一下,我正在使用自签名证书在本地主机上测试这一点,但理论上这应该是不相关的(?)
发布于 2018-08-13 21:51:52
当您将X-Content-Type-Options设置为nosniff时,您还必须在NGINX中设置允许的类型。为了做到这一点,你只需要参考他们的文件:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# ...
}https://stackoverflow.com/questions/51818185
复制相似问题