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

HowTo: Verify My NTP Working Or Not

You can use any one of the following program to verify ntp client configuration: ntpq -...

Bash Shell Generate Random Numbers

How do I create or generate random numbers (sequence of numbers that lack any pattern), under...

Nginx Force (Redirect) WWW.Domain.COM To Domain.COM

I know how to force and redirect www.example.com to example.com under Lighttpd web server. How do...

SUSE Linux Restart / Stop / Start Network Service

Task: Start Network Service # /etc/init.d/network start # /etc/init.d/network start eth0 Task:...

Linux: Check For Memory Leaks In Programs

How do I check my C programs under Linux operating systems for memory leaks? How do I debug and...