nginx.conf忽略nginx-ingress配置映射片段

我有一个kubernetes集群,我使用helm nginx-ingress chart部署了一个Nginx入口控制器.

我需要在Nginx-controller-pod中生成Nginx.conf文件添加一些自定义配置,我看到一个问题,如果我添加一行选项,如proxy-buffer-size:“512k”I可以看到这反映在Nginx.conf文件中,一切都按预期工作.

但是,如果我尝试添加一个片段来完成同样的事情:

location-snippet: |
  proxy_buffer_size "512k";

就好像Nginx.conf文件忽略了它,proxy_buffer_size设置保持认值.

我需要能够添加http-snippet,server-snippet和location-snippet覆盖,但是我是否尝试将它们添加到ConfigMap或作为Ingress.yaml文件中的注释,它们总是被忽略.

我的Ingress yaml文件

apiVersion: extensions/v1beta1
kind: Ingress
Metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: Nginx
    ingress.kubernetes.io/ssl-redirect: "true" 
    ingress.kubernetes.io/secure-backends: "true"    
    ingress.kubernetes.io/force-ssl-redirect: "true"

    ingress.kubernetes.io/location-snippet: |
       proxy_buffer_size 512k;     --This does not update the Nginx.conf
spec:
  tls:
  - hosts:
    - my.app.co.uk
    secretName: tls-secret

  rules:
  - host: my.app.co.uk
    http:
      paths:
      - path: /
        backend:
          serviceName: myappweb-service
          servicePort: 80

我的Nginx配置图:

apiVersion: v1
kind: ConfigMap
Metadata:
  labels:
    app: nginx-ingress
    chart: nginx-ingress-0.28.3
    component: controller
    heritage: Tiller
    release: nginx-ingress
  name: nginx-ingress-controller
  namespace: default
data:
  proxy-buffer-size: "512k" -- this works and updates the Nginx.conf

  location-snippet: |
    proxy_buffers 4 512k; -- this does not update the Nginx.conf

  server-snippet: |       -- this does not update the Nginx.conf
    location /messagehub {
      proxy_set_header Upgrade $http_upgrade;
      proxy_http_version 1.1;
      proxy_set_header X-Forwarded-Host $http_host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header Connection "upgrade";
      proxy_cache_bypass $http_upgrade;
   }
如果您想修改Kubernetes Ingress,注释选项如下:

> Nginx.ingress.kubernetes.io/configuration-snippet用于Nginx位置块代码
> Nginx.ingress.kubernetes.io/server-snippet,用于Nginx配置服务块中的代码

看起来你正在使用Nginx.org/location-snippets:对于那种情况.

Nginx配置示例中还有一个YAML无效语法,并且您应该根据此example在服务器片段中使用复数.在撰写本文时,docs中存在拼写错误.开放this ticket跟进.

它应该是这样的:

  server-snippets: |
    location /messagehub {
      proxy_set_header Upgrade $http_upgrade;
      proxy_http_version 1.1;
      proxy_set_header X-Forwarded-Host $http_host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header Connection "upgrade";
      proxy_cache_bypass $http_upgrade;
      }

而不是这个:

  server-snippet: |
    location /messagehub {
      proxy_set_header Upgrade $http_upgrade;
      proxy_http_version 1.1;
      proxy_set_header X-Forwarded-Host $http_host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header Connection "upgrade";
      proxy_cache_bypass $http_upgrade;
    }

注意最后一个花括号的缩进.

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...