【发布时间】:2018-05-11 21:50:55
【问题描述】:
我正在运行带有 nginx 入口的 k8s。它指向 https://www.example.com/app 某个 pod,将“/app”重写为“/”,应用监听 80 并提供“/”:
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
labels:
app: example
name: example
namespace: default
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
serviceName: app
servicePort: 80
path: /app
- backend:
serviceName: app
servicePort: 80
path: /app/
tls:
- hosts:
- www.example.com
secretName: example-tls
如果我将 https://www.example.com/app 请求传递给 pod 并且 pod 以另一个 URL 响应(例如 /content),我的浏览器显示https://www.example.com/content - 它是 404,因为没有“/”的入口规则内容”。 AFAIK nginx 可以使用 sub_filter 重写响应。另一种方法是开发具有一些可配置路径前缀的应用程序。我也可以使用base_url,但只能使用html。但是有没有简单的方法来传递前缀作为回报,所以如果 pod return "/content" nginx 将其重写为https://www.example.com/app/content
谢谢。
【问题讨论】:
-
您的用例是什么?为什么需要这个前置?为什么app不能直接返回所有的URL?
-
有些应用可以并且正在做,但是有些开发者不会添加这个功能,并要求我想办法什么时候nginx会做。
标签: nginx kubernetes