nginx: Send Custom HTTP Headers

How do I send or set arbitrary HTTP headers using nginx web server?

You need to use add_header directive. It sends arbitrary HTTP header when the response code is equal to 200, 204, 301, 302 or 304. You must compile nginx with NginxHttpHeadersModule. Once compiled edit nginx.conf:
# vi nginx.conf
Add the headers as follows in http, server, or location section:

add_header name value

In this example, set X-Whom to www-node01:

add_header X-Whom www-node01

Save and close the file. Reload nginx:
# /usr/local/nginx/sbin/nginx -s reload

How Do I Test It?

Simply use curl as follows:
$ curl -I example.com
Sample outputs:

HTTP/1.1 200 OK
Server: nginx
Date: Mon, 15 Mar 2010 10:40:58 GMT
Content-Type: text/html; charset=ISO-8859-1
Connection: keep-alive
X-Whom: www-node01

Was this answer helpful?

 Print this Article

Also Read

tcpdump: Monitor ALL eth1 Traffic Except My Own SSH Session

I'm using tcpdump to dump, debug and monitor traffic on a network. However, there is lots of...

Linux Default Services Which Are Enabled at Boot

Can you provide a guidance on default CentOS / Fedora / RHEL / Redhat enterprise Linux services...

Linux RAM Disk: Creating A Filesystem In RAM

Software RAM disks use the normal RAM in main memory as if it were a partition on a hard drive...

Linux/UNIX: Configure OpenSSH To Listen On an IPv6 Address

How do I enable OpenSSH SSH server to listen on an IPv6 address under Linux or UNIX operating...

Yum issues with low memory plans (Resolution)

If you are getting yum errors on our 128 or 192 yearly plans with the CentOS/Fedora distro then...