APISix: Load Balancing how to pass a response header based on the upstream server identity

132 Views Asked by At

Totally new to API Six and I am wondering if there is a way to pass a fictious response header identifying the server. Not real identifying information but one that our support people can use to cross reference the true identity of the server.

Have not tried anything as of yet.

1

There are 1 best solutions below

0
Tsal Troser On

You can use response-rewrite plugin to set a custom response headers or body. You can set a custom Header value or Nginx variables.

"routes": {
    "id": 1,
    "uri": "/test/serverA",
    "plugins": {
        "response-rewrite": {
            "headers": {
                "set": {
                    "X-Server-id": "A",
                    "X-Upstream-Server-ip": "$server_addr"
                }
            }
        }
    },
    "upstream": {
        "nodes": {
            "127.0.0.1:80": 1
        }
    },
    "id": 2,
    "uri": "/test/serverB",
    "plugins": {
        "response-rewrite": {
            "headers": {
                "set": {
                    "X-Server-id": "B"
                }
            }
        }
    },
    "upstream": {
        "nodes": {
            "127.0.0.1:81": 1
        }
    }
}