Add Custom HTTP Header to Oracle Cloud Load Balancer

An application load balancer on Oracle Cloud Infrastructure works on layer 7, so it supports both HTTP and HTTPS. It can distribute HTTP and HTTPS traffic based on host-based or path-based rules. An application load balancer is a context-aware load distribution that can forward and manipulate requests based on HTTP headers. It also has a configurable range of health check status codes, and additionally based on the requirements on backend servers custom request and response headers can be inserted.

Today, we will be talking about adding custom http request or response header. There are customer requirements which requires to add custom headers based on how the backend application is designed.

How Custom Headers work

Custom request and response headers allow you to specify additional headers that the load balancer adds to requests and responses. These rules enable you to offer metadata to your backend servers, enabling you to do things like figure out which listener made a request, geographic location of the client’s IP address, notify WebLogic that the Load Balancer Terminated SSL and so on.

Application Load balancer adds certain headers by default to all HTTP(S) requests and responses that it proxies between backends and clients. For more information, see https://docs.oracle.com/en-us/iaas/Content/Balance/Reference/httpheaders.htm

In this example, customer wants to replicate their existing on-prem environment by adding a specific HTTP header as CLIENTIP with the value of actual client IP using X-Forwarded-For or X-REAL-IP.

Before we go through the steps, lets understand about What is a rule set?

A rule set is a named collection of rules connected with a load balancer and applied to one or more load balancer listeners. You must first establish the rule set that contains the rules before you can apply it to a listener. Rules are objects that represent actions taken by a load balancer listener on traffic. The load balancer’s setup includes the rule set. When you create or edit a load balancer listener, you may specify the rule set to use. A rule set can contain the following sorts of rules:

Below are steps to add customize request header to OCI LB:

  1. Login to the OCI console – https://cloud.oracle.com/
  2. Navigate to –

Networking > Load Balancers > Select your load balancer and view details

3. Scroll down on the left-hand side
  • Select Rule Sets > Select Create Rule set > Give a Name > Select Specify Request Header Rules and select the Action “Add Request Header”.
  • Type in the Header name as per the variable or name user wants and select the value as {X-Real-IP} or {X-Forwarded-For}.

See the screenshot below, note I have chosen different Header names to show different values

  1. Save changes to save the Ruleset.
  2. Select Listeners under the same page –

Edit the Listener > Scroll down to Rulesets and attach the Ruleset created in Step 4 to the Listener. This will apply the ruleset to the Load Balancer Listener.

Now the configuration is complete . Let’s check from the backend server instance, where we can see the inserted custom header being received on the instance with the actual client-Ip used to test the load-balancer. We have used the below tcpdump command to check the same: tcpdump -Xx -s 0 -i <INTERFACE> port <PORT_NUM> | grep <Filter> -A 2 -B 2

As we can see in the screenshots above, a new custom header with the value of CLIENTIP and CLIENTip with the value of X-Forwarded-For and X-Real-IP (actual client IP address) is passed to the backend server.

Hope, this information was helpful.

I will also like to Thank my colleague Piyush Jalan (https://www.linkedin.com/in/piyush-jalan/) for his contribution to this blog.

Leave a comment