Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am using two system (both are nginx load balancer and one act as an backup). I want to add and use few http custom headers. Please give your suggestion

e.g

  upstream upstream0{
            #list of upstream servers
            server backend:80;
            server backup_load_balancer:777 backup;
            #healthcheck
  }

  server{
        listen  80;
        #Add custom header about the port and protocol  (http or https)
        server_name     _;
        location / {
                proxy_pass "http://upstream0;#" is included since links are not allowed in the post
        }

   }

//Backup system

server{
        listen  777;
        server_name     _;
        #doing some other extra stuf

        #use port and protocol to direct
}

Thanks

share|improve this question

1 Answer 1

If you want to add headers then you want something like this:

server {
    listen  80;
    server_name     _;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Frame-Options sameorigin;
    add_header X-UA-Compatible "IE=Edge,chrome=1";
    add_header X-Your-Port-Header-Here $server_port;
    add_header X-Your-Protocol-Header-Here $scheme;
    set $yourcustomheader $scheme$server_port;
    add_header X-Your-Custom-Header $yourcustomheader;
    location / {
            proxy_pass http://upstream0;
    }

}

You can reference the following variables in Nginx. If the above doesn't provide enough flexibility for you then take a look at the HttpHeadersMore module, but note that is not provided in most standard Nginx distributions so you may have to compile it yourself. If you use Debian, though, then you can find it in the nginx-extras package from Dotdeb.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.