How to convert Nginx configuration to nginx-ingress?

2/28/2019

I have nginx with following configuration:

  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  client_max_body_size 1g;
  client_body_buffer_size 128k;
  proxy_connect_timeout 120;
  proxy_send_timeout 240;
  proxy_read_timeout 240;
  proxy_buffers 32 4k;

  proxy_hide_header Strict-Transport-Security;
  proxy_hide_header Content-Type;
  add_header Content-Type application/json;

I would like to translate my nginx config to kubernetes ingress-nginx (Ingress resource). Is there a way to implement this config using kubernetes Ingress resources? Reading ingress-nginx docs I haven't found how to map proxy_pass or multiple rewrites to Ingress resource. I would appreciate ref to some detailed doc or sample with similar config.

-- August Gerro
kubernetes
nginx
nginx-ingress

1 Answer

3/21/2019

Yes can do it using Snippets and Custom Templates as explained here in NGINX Ingress Controller documentation by nginxinc.

Example of using Snippets via ConfigMap:

---
# Source: nginx-ingress/templates/controller-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
  labels:
    app.kubernetes.io/name: nginx-ingress
    helm.sh/chart: nginx-ingress-0.3.4
    app.kubernetes.io/managed-by: Tiller
    app.kubernetes.io/instance: RELEASE-NAME
data:
   server-snippets: |
    location /helloworld {
      proxy_redirect off;
      proxy_http_version 1.1;
    }
-- Nepomucen
Source: StackOverflow