Adding and using header (HTTP) in nginx

Solution 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.