gpt4 book ai didi

nginx - 重写nginx入口的路径

转载 作者:行者123 更新时间:2023-12-02 11:44:43 26 4
gpt4 key购买 nike

我需要将Ingress指向图片,这样我的Pod才能完整获取网址。我有以下配置:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: solar-demo
annotations:
nginx.org/server-snippet: "proxy_ssl_verify off;"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: shmukler.example.com
http:
paths:
- path: /city/*
backend:
serviceName: solar-demo
servicePort: 3000
- path: /solar/*
backend:
serviceName: solar-demo
servicePort: 3001

如果我保持一行: nginx.ingress.kubernetes.io/rewrite-target: /,我在Pods中的服务将获得重写的路径,因此 /city/dublin变为 /dublin

如果我注释掉 nginx.ingress.kubernetes.io/rewrite-target: /行,我只会在客户端得到 503错误,而日志中什么也没有。通过重写,我的服务会给我 404,因为没有路由 /dublin

我究竟做错了什么?我如何才能继续前进并让Pod做出回应?
$ kubectl describe svc solar-demo
Name: solar-demo
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration=
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"solar-demo","namespace":"default"},"spec":{"ports":[{"name":"city","port":3000...
Selector: app=testapp
Type: ClusterIP
IP: 10.107.221.76
Port: city 3000/TCP
TargetPort: 3000/TCP
Endpoints: 172.17.0.3:3000,172.17.0.8:3000
Port: solar 3001/TCP
TargetPort: 3001/TCP
Endpoints: 172.17.0.3:3001,172.17.0.8:3001
Session Affinity: None
Events: <none>

有什么建议吗?

最佳答案

这应该是一个有效的配置:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: solar-demo
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: shmukler.example.com
http:
paths:
- path: /city
backend:
serviceName: solar-demo
servicePort: 3000
- path: /solar
backend:
serviceName: solar-demo
servicePort: 3001

发生了什么变化:
  • 从路径
  • 中删除了 *
  • 批注
  • 中指定的入口
  • 删除了重写注释

  • 入口上的 path(使用 nginx入口时)就像指定nginx location块。 nginx在位置块中不使用 *字符。

    关于nginx - 重写nginx入口的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51174025/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com