我有以下配置:
daemonset:
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: nginx-ingress
namespace: nginx-ingress
spec:
selector:
matchLabels:
app: nginx-ingress
template:
metadata:
labels:
app: nginx-ingress
spec:
serviceAccountName: nginx-ingress
containers:
- image: nginx/nginx-ingress:1.4.2-alpine
imagePullPolicy: Always
name: nginx-ingress
ports:
- name: http
containerPort: 80
hostPort: 80
- name: https
containerPort: 443
hostPort: 443
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
args:
- -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
- -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
主要配置:
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
namespace: nginx-ingress
data:
proxy-set-headers: "nginx-ingress/custom-headers"
proxy-connect-timeout: "11s"
proxy-read-timeout: "12s"
client-max-body-size: "5m"
gzip-level: "7"
use-gzip: "true"
use-geoip2: "true"
自定义标题:
apiVersion: v1
kind: ConfigMap
metadata:
name: custom-headers
namespace: nginx-ingress
data:
X-Forwarded-Host-Test: "US"
X-Using-Nginx-Controller: "true"
X-Country-Name: "UK"
我遇到以下情况:
否则,一切正常,控制器日志显示我唯一的后端(转储标头的expressJs应用)正确地是服务器,得到了预期的响应,依此类推。
我已经从github上的示例中复制了尽可能多的内容,进行了最少的更改,但没有任何结果(包括查看自定义标头的示例时)。
任何想法或指示都将不胜感激。
谢谢!
答案 0 :(得分:2)
Use ingress rule annotations.
Example:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "server: hide";
more_set_headers "X-Content-Type-Options: nosniff";
more_set_headers "X-Frame-Options: DENY";
more_set_headers "X-Xss-Protection: 1";
name: myingress
namespace: default
spec:
tls:
- hosts:
I used nginx server 1.15.9
答案 1 :(得分:1)
您似乎使用的是NGINX本身的kubernetes-ingress而不是社区nginx入口控制器ingress-nginx。
如果您看到kubernetes-ingress的supported ConfigMap keys,则不支持gzip
选项。如果您看到ConfigMap options用于ingress-nginx,则会看到所有可以配置的gzip密钥。
尝试切换到community nginx入口控制器。
答案 2 :(得分:1)
对于后代: nginx社区控制器=> quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.21.0
nginx kubernetes控制器=> nginx / nginx-ingress:edge(如文档所示)
社区的自定义标头configmap =>代理设置标头:“ nginx-ingress / custom-headers”
kubernetes的自定义标头配置映射=>添加标头:“ nginx-ingress / custom-headers”
答案 3 :(得分:1)
使用 Helm 进行 kubernetes/ingress-nginx 安装时。设置您的自定义标题,例如。 My-Custom-Header 为
controller:
addHeaders:
X-My-Custom-Header: Allow
这将在根据 https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#add-headers 向客户端发送响应流量之前添加自定义标头 您可以在日志中访问它:
controller:
log-format-upstream: '{"x-my-custom-header" : "$http_x-my-custom-header"}'
答案 4 :(得分:1)
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_input_headers "headername: value";