我有一个Angular 4应用程序,我在亚马逊ec2机器上使用docker部署了它。我正在使用CloudFlare来管理我的域名系统。
问题出在Chrome上,当我尝试刷新页面时,它返回的不是网页,而是index.If的html代码。我从机器上通过IPV4直接访问页面,应用程序运行良好。
在Firefox/Safari上,一切都像预期的那样工作。
这是我的index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PageName</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Serif|Roboto" rel="stylesheet">
<link rel="icon" type="image/x-icon" href="assets/menu/favicon.png">
<link rel="manifest" href="./manifest.json">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
</head>
<body>
<div id="global_root">
<app-root></app-root>
</div>
<script type="text/javascript" src="inline.bundle.js">
</script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>
以下是来自IPV4的响应头:
Connection: keep-alive
Date: Fri, 04 Jan 2019 14:25:56 GMT
Server: nginx/1.15.7
Transfer-Encoding: chunked
X-Powered-By: Express
以下是通过cloudflare的响应头部:
cf-ray: 493e5f00093f9706-FRA
date: Fri, 04 Jan 2019 14:24:51 GMT
expect-ct: max-age=604800,
report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
status: 200
strict-transport-security: max-age=2592000; includeSubDomains
x-content-type-options: nosniff
x-powered-by: Express
发布于 2019-01-04 23:40:13
看起来你没有设置Content-Type
头文件,Cloudflare将X-Content-Type-Options: nosniff
添加到所有响应中,Chrome将其应用于文档,而火狐和Safari不会将其应用于文档(仅适用于样式表和脚本)。
Express在默认情况下设置了Content-Type: text/html; charset=UTF-8
,所以可能会有一些奇怪的事情--您到底是如何为这个文档提供服务的?您可以尝试显式地使用res.type("html")
。
https://stackoverflow.com/questions/54025515
复制相似问题