kubernetes入口在重写目标上返回不正确的模拟型

发布于 2025-01-22 13:54:41 字数 1454 浏览 2 评论 0原文

我在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 with
content-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分開簡單 2025-01-29 13:54:41

不知何故,入口响应content-type:text/html,就好像它正在处理飞行前的CORS请求解决方案是在Ingress上禁用Cors 并将其配置在应用程序上。

apiVersion: networking.k8s.io/v1 
kind: Ingress
metadata:
  annotations:
    ...
    nginx.ingress.kubernetes.io/enable-cors: "false"
    ...

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.

apiVersion: networking.k8s.io/v1 
kind: Ingress
metadata:
  annotations:
    ...
    nginx.ingress.kubernetes.io/enable-cors: "false"
    ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文