[英]NGINX controller Kubernetes: need to change Host header within ingress
I'm running NGINX and Kube.netes.我正在运行 NGINX 和 Kube.netes。 I need to configure NGINX so that it sets or overrides the Host header Host: minio:9000
to a pod so that the Pod will always service requests thinking that it's hosting as minio:9000
no matter where the request is coming from.我需要配置 NGINX 以便它将 Host header Host: minio:9000
设置或覆盖到 pod,这样 Pod 将始终为请求提供服务,认为它作为minio:9000
托管,无论请求来自何处。 I believe the recommended approach is to use NGINX and modify the ingress annotations of that Pod (maybe I'm wrong).我相信推荐的方法是使用 NGINX 并修改该 Pod 的入口注释(也许我错了)。
I instead my nginx controller with helm via this guide https://kube.netes.github.io/ingress-nginx/deploy/#using-helm我通过本指南https://kube.netes.github.io/ingress-nginx/deploy/#using-helm 而不是我的 nginx controller
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install my-release ingress-nginx/ingress-nginx
I declared my ingress like this.我这样宣布我的入口。 Guides have suggested I use nginx annotations on the ingress YAML.指南建议我在入口 YAML 上使用 nginx 注释。
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: {{ template "fullname" . }}
labels:
chart: {{ template "chartVersion" . }}
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_input_headers 'Host: minio:9000';
spec:
rules:
- host: {{ .Values.ingress.host }}
http:
paths:
- path: /
backend:
serviceName: {{ template "fullname" . }}
servicePort: {{ .Values.deployment.servicePort }}
Many guides have said this would work.很多导游都说这样可以。 I've tried我试过了
nginx.ingress.kubernetes.io/upstream-vhost: minio:9000
I've also tried我也试过
nginx.ingress.kubernetes.io/configuration-snippet: |
access_by_lua_block {
ngx.var.best_http_host = 'minio:9000';
}
None of these methods seem to change the host header from inside the cluster.这些方法似乎都没有从集群内部更改主机 header。 If I do如果我做
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Host 'minio:9000';
I get a 400 response saying too many Host
headers (which seems to be caused by the Pod running Go).我收到一个 400 响应,说Host
标头过多(这似乎是由运行 Go 的 Pod 引起的)。 But at least I know the annotations are being picked up by nginx.但至少我知道注释正在被 nginx 拾取。
Turns out it was by my other annotation nginx.ingress.kube.netes.io/rewrite-target: /$1
stripping the path inside the cluster.结果是我的另一个注释nginx.ingress.kube.netes.io/rewrite-target: /$1
剥离了集群内的路径。 Getting rid of this annotation makes the ingress work as intended.摆脱这个注释使入口按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.