[英]Kubernetes Nginx Reverse Proxy Return URL
I'm running k8s with nginx ingress. 我正在使用Nginx Ingress运行k8s。 It's pointing https://www.example.com/app at some pod with rewrite "/app" to "/", app listen 80 and serves "/":
它将https://www.example.com/app指向某个pod,将“ / app”重写为“ /”,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
If i'm going to https://www.example.com/app request passed to pod and pod responded with another URL (/content for example), and my browser shows me https://www.example.com/content - it's 404, because there is no ingress rule for "/content". 如果我要转到https://www.example.com/app,则传递到pod的请求和pod将以另一个URL(例如,/ content)进行响应,并且我的浏览器向我显示https://www.example.com/content -它是404,因为“ / content”没有入口规则。 AFAIK nginx can rewrite response with sub_filter.
AFAIK nginx可以使用sub_filter重写响应。 Another way is to develop app with some configurable path prefix.
另一种方法是使用一些可配置的路径前缀来开发应用程序。 Also i can use base_url, but only with html.
我也可以使用base_url,但只能用于html。 But is there simple way to pass prefix in return, so if pod return "/content" nginx rewrites it to https://www.example.com/app/content
但是有没有简单的方法可以传递前缀作为返回值,因此,如果pod返回“ / content”,nginx会将其重写为https://www.example.com/app/content
Thank you. 谢谢。
But is there simple way to pass prefix in return, so if pod return "/content" nginx rewrites it to https://www.example.com/app/content
但是有没有简单的方法可以传递前缀作为返回值,因此,如果pod返回“ / content”,nginx会将其重写为https://www.example.com/app/content
No, there is no simple way to make it by Ingress rules. 不,没有简单的方法可以通过Ingress规则实现。
It is possible by Nginx itself, but not implemented in Nginx-Ingress. Nginx本身可以实现,但不能在Nginx-Ingress中实现。
I highly recommend you to return the right path from the application. 我强烈建议您从应用程序返回正确的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.