Custom Header not getting added in traefik proxy

Custom headers are not getting added in traefik proxy due to which AWS load balancer rule is not working as expected when i add a rule for http header.

http:
  routers:
    rate-service-route:
      rule: "PathPrefix(`/rate-service/{path:.*}`)"
      service: rate
      entryPoints:
        - port9090
      priority: 60
      middlewares:
        - customHeaders
  middlewares:
    customHeaders:
      headers:
        customRequestHeaders:
          x-service-name: rate
  services:
    rate:
      loadBalancer:
        servers:
          - url: http://test-route.xyz.com

Share your full Traefik static and dynamic config, and docker-compose.yml if used.

Format your code with 3 backticks in front and after, or select the code and press </> . In yaml every space matters. And it makes it so much more readable for people trying to help you.

hey @bluepuma77 , i found the issue, apparently when i use x-service-name in all small cases the header is not getting passed, i changed to X-Service-Name and it is working as expected.

http:
  routers:
    rate-service-route:
      rule: "PathPrefix(`/rate-service/{path:.*}`)"
      service: rate
      entryPoints:
        - port9090
      priority: 60
      middlewares:
        - customHeaders
  middlewares:
    customHeaders:
      headers:
        customRequestHeaders:
          X-Service-Name: rate
  services:
    rate:
      loadBalancer:
        servers:
          - url: http://test-route.xyz.com

Do you know the reason why this would happen?

Hey sorry for the above text, this is a bit intermittent, it is not working now.
Can you check what is the issue here.

According to doc it should look like this:

http:
  middlewares:
    testHeader:
      headers:
        customRequestHeaders:
          X-Script-Name: "test"

And you need to assign the middleware by name to the router.

Just tested, works for me, whoami shows X-Script-Name: test.

1 Like

Works for me now, i had multiple route files and after making changes in all, it stopped working, the issue was i had kept the middleware name as same in all and it was causing this issue.

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