Snippets add_header doesn't work with all applications

My issue: The snippets “add_header“ doesn’t show/works with all ingress applications

How I encountered the problem: I’m installing NGINX Ingress Controller Community as an alternative to Ingress-Nginx, I’m testing Ingress annotations and needed to add a header for example to enable CORS u other value.

Solutions I’ve tried:

Version of NIC and/or NGINX: helm chart nginx-ingress-2.4.3, app version 5.3.3 and kubernetes 1.34.2

Deployment environment:

Install with helm:

helm install nginx-ingress oci://ghcr.io/nginx/charts/nginx-ingress \
--version 2.4.3 \
--set controller.service.type=NodePort \
--set controller.service.externalTrafficPolicy=Local \
--set controller.hostNetwork=true \
--set controller.kind=daemonset \
--set controller.enableCustomResources=true \
--set controller.wildcardTLS.secret=default/my-ssl \
--set controller.defaultTLS.secret=default/my-ssl \
--set controller.enableSnippets=true

1 ) Success case

Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.org/server-snippets: |
      add_header my-test-header test-value;
  name: nginx-prod
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: nginx-prod.mysite.com
    http:
      paths:
      - backend:
          service:
            name: nginx-prod
            port:
              number: 8080
        path: /
        pathType: ImplementationSpecific
  tls:
  - hosts:
    - nginx-prod.mysite.com
    secretName: my-ssl

Example curl

curl https://nginx-prod.mysite.com --head

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 13 Feb 2026 18:18:30 GMT
Content-Type: text/html
Content-Length: 615
Connection: keep-alive
Last-Modified: Wed, 04 Feb 2026 15:12:20 GMT
ETag: "698361d4-267"
Accept-Ranges: bytes
my-test-header: test-value --> Correct
  1. Error case
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    annotations-risk-level: Critical
    nginx.org/location-snippets: |
      add_header my-test-header test-value;
  name: app1
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: app1.mysite.com
    http:
      paths:
      - backend:
          service:
            name: app1
            port:
              number: 3000
        path: /
        pathType: ImplementationSpecific
  tls:
  - hosts:
    - app1.mysite.com
    secretName: my-ssl

Example curl

curl https://app1.mysite.com --head

HTTP/1.1 404 Not Found -> Real reply from my app1 because need more data
Server: nginx
Date: Fri, 13 Feb 2026 18:28:38 GMT
Content-Type: text/html
Content-Length: 146
Connection: keep-alive

NOTE: I know is not the same, but with ingress-nginx app1 . mysite . com it works correctly.

HTTP/1.1 404 Not Found
Date: Fri, 13 Feb 2026 18:33:04 GMT
Connection: keep-alive
Vary: Origin
Strict-Transport-Security: max-age=31536000; includeSubDomains
my-test-header: test-value --> Correct

Hi @VictorCisternas !

I think the issue here is inheritance. Could you try this? Module ngx_http_headers_module

1 Like

@Micheal_Kingston Thank you, in the documentation you sent me, I understand that it may be because the application is responding with a 404 code and add_header supports other codes.

Anyway, perform the tests without changes:

    nginx.org/server-snippets: |
      add_header_inherit merge;
      add_header Access-Control-Allow-Origin *;
or:
    nginx.org/server-snippets: |
      add_header_inherit on;
      add_header Access-Control-Allow-Origin *;
or:
    nginx.org/server-snippets: |
      add_header_inherit off;
      add_header Access-Control-Allow-Origin *;
or:
    nginx.org/server-snippets: |
      add_trailer_inherit merge;
      add_header Access-Control-Allow-Origin *;
or:
    nginx.org/server-snippets: |
      add_trailer_inherit on;
      add_header Access-Control-Allow-Origin *;
or:
    nginx.org/server-snippets: |
      add_trailer_inherit off;
      add_header Access-Control-Allow-Origin *;
or:
    nginx.org/server-snippets: |
      add_header_inherit merge;
      add_trailer_inherit merge;
      add_header Access-Control-Allow-Origin *;
or:
    nginx.org/server-snippets: |
      add_header_inherit on;
      add_trailer_inherit on;
      add_header Access-Control-Allow-Origin *;
or:
    nginx.org/server-snippets: |
      add_header_inherit off;
      add_trailer_inherit off;
      add_header Access-Control-Allow-Origin *;

Now I understand the cause, I’ll try to run some more tests, thanks!!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.