Report this

What is the reason for this report?

How to add header to existing Load Balancer while adding header is not available within its'settings?

Posted on January 9, 2020

I have load balancer that balance traffic on droplets which are running using kubernates and I want add header while settings don’t contain anything about header.There are only Forwarding rules, Algorithm, SSL …etc.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

Because DigitalOcean Load Balancers are network load balancers, not application load balancers, they do not support directing traffic to specific backends based on URLs, cookies, HTTP headers, etc.

The Load Balancer feature set primarily focuses on distributing incoming network traffic across multiple Droplets to ensure your applications remain available and responsive.

However, there’s a workaround that you could use for this limitation. You can use a reverse proxy (like Nginx or HAProxy) installed on your Droplets to add or change HTTP headers as necessary.

Here’s a simple example of how to add a header using Nginx:

  1. Install Nginx on your Droplets.

  2. Edit your Nginx configuration file (commonly found at /etc/nginx/nginx.conf or /etc/nginx/sites-available/default).

  3. In the location block where you want to add the header, add the add_header directive. For example, to add a header named X-My-Header with the value My Value, you would add:

location / {
    add_header X-My-Header "My Value";
    # ...
}
  1. Save your changes and exit the text editor.

  2. Test your configuration file to make sure there are no syntax errors:

sudo nginx -t
  1. If the configuration test is successful, reload Nginx to apply the changes:
sudo systemctl reload nginx

Keep in mind that the add_header directive will not add a header to proxied requests, it adds headers to the response that Nginx sends back to the client.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.