J.L
J.L

Reputation: 75

AWS ELB Custom Headers Nginx

A strange behavior of ELB where custom HTTP headers are being dropped. I am currently using Nginx as the server with the following virtual host configuration:

server {
    listen 80;
    server_name example.com;
    location / {
        index index.html index.htm;
        add_header Custom Test;
    }
}

By direct accessing the server using IP address, header "Custom: Test" can be found. But once this server resides behind an ELB. The custom header no longer show. May I know if this is an issue with my setup?

Upvotes: 3

Views: 3692

Answers (1)

alexjs
alexjs

Reputation: 573

At the time of response, I was able to consistently get the ELB to return all Response headers I tested - including those with _, however I will attempt to answer the question anyway.

From the documentation:

When you use HTTP (layer 7) for both front-end and back-end connections, your load balancer parses the headers in the request and terminates the connection before sending the request to the back-end instances. [...]

Not all HTTP extensions are supported in the load balancer. You may need to use a TCP listener if the load balancer is not able to terminate the request due to unexpected methods, response codes, or other non-standard HTTP 1.0/1.1 implementations.

This could be what results in the ELB dropping some headers. There isn't a definitive list of what it does or doesn't drop, but it implies anything non-RFC (non-standard HTTP 1.0/1.1 implementations)

If you need a custom header to be persisted where you're consistently observing it failing, then you can use a TCP LB instead. You'll lose things like X-Forwarded-For (but you can use the Proxy protocol to fetch this info) and Session Stickiness.

For the case of underscores - this is a little discouraged (at least with Nginx or other webservers) may have differing behaviour.

Upvotes: 3

Related Questions