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

TightVNC Desktop

1. Installing the required packages   The server package is called 'vnc-server'. Run the...

PHP Increase Upload File Size Limit

Your php installation putting limits on upload file size. The default will restrict you to a max...

How do I find out System / Server Memory Utilization

free command example Type the free command at shell prompt: $ free $ free -m Output:...

CentOS / Redhat: Create Software RAID 1 Array

RAID devices are virtual devices created from two or more real block devices. Linux supports...

Changing Default SSH port From 22

nano /etc/ssh/sshd_configLook for#Port 22Change "22" to the port you wish to use.CTRL + X, Save...