kubernetes入口在重写目标上返回不正确的模拟型
我在K8S版本的内容响应中遇到问题:1.20.15
,将入口重定向到基于同一域的2个应用程序(Bellow是假设的)。一种服务是API,另一个服务是网站。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTP
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
labels:
app.kubernetes.io/name: frontend-explorer
name: frontend-explorer
spec:
rules:
- host: dev-explorer.test.org
http:
paths:
- path: /(.*)
pathType: Prefix
backend:
service:
name: frontend-explorer-svc
port:
number: 8081
- path: /api/(.*)
backend:
service:
name: backend-explorer-svc
port:
number: 3000
dev-explorer.test.org/api/settings
之类的请求将转发到backend-ecplorer-svc
,其URL将成为dev-explorer。 test.org/
,对于后端服务,
服务似乎没有任何问题,但是当访问https://dev-explorer.test.org
时,有错误的
Loading module from “https://dev-explorer.test.org/main-es2015.3c58a0782b71050b1782.js”
was blocked because of a disallowed MIME type (“text/html”).
错误可以使用卷曲来获取内容,但是入口响应 content-type:text/html
而不是content-type:application/js
,强迫浏览器阻止网站,
不确定这是入口上的问题吗? JS代码自我。关于如何获得正确的content-type
的任何想法?
I am having a problems with content response from a k8s version: 1.20.15
, the ingress redirects to 2 applications based on the same domain (domains bellow are hypothetical). One service being an API and the other a website.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTP
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
labels:
app.kubernetes.io/name: frontend-explorer
name: frontend-explorer
spec:
rules:
- host: dev-explorer.test.org
http:
paths:
- path: /(.*)
pathType: Prefix
backend:
service:
name: frontend-explorer-svc
port:
number: 8081
- path: /api/(.*)
backend:
service:
name: backend-explorer-svc
port:
number: 3000
A request like dev-explorer.test.org/api/settings
will be forward to the backend-explorer-svc
and its url will become dev-explorer.test.org/
, to the backend service
The services seem to working without any problems, but when accessing https://dev-explorer.test.org
, there are errors like:
Loading module from “https://dev-explorer.test.org/main-es2015.3c58a0782b71050b1782.js”
was blocked because of a disallowed MIME type (“text/html”).
You can use a curl to fetch the content, but the ingress responds withcontent-type: text/html
instead of content-type: application/js
, forcing the browser to block the website
Not certain if this is a problem on the ingress, or the JS code it self. Any ideas on how to get the correct content-type
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知何故,入口响应
content-type:text/html
,就好像它正在处理飞行前的CORS请求解决方案是在Ingress上禁用Cors 并将其配置在应用程序上。Somehow the ingress was responding with
content-type: text/html
as if it was dealing with a pre-flight CORS request The solution was to disable CORS on ingress and configure it on the app.