How do I send a header to my Web server (such as Nginx / Lighttpd / Apache / ISS) on a Apple OS X or Unix or Linux based system using a curl command line option for testing and debugging my web apps or server nodes behind a load balancer?
The curl command supports -H or --header option to pass extra HTTP header to use when getting a web page from your web server. You may specify any number of extra headers. When you add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. The syntax is:
curl -H 'YOUR-EXTRA-HEADER-HERE' apache-server-ip curl -H 'YOUR-EXTRA-HEADER-1-HERE' -H 'YOUR-EXTRA-HEADER-2-HERE' www.cyberciti.biz
For example, send Host header to www.cyberciti.biz to get HTML response from 75.126.153.206:80, run:
curl -H 'Host: www.cyberciti.biz' 75.126.153.206:80
This is also useful when 75.126.153.206 has multiple virtual host set. The default is not to response anything when virtual host header is not sent:
$ curl -I 75.126.153.206:80
Sample outputs:
HTTP/1.1 500 Internal Server Error Server: nginx Date: Wed, 31 Oct 2012 18:51:03 GMT Content-Type: text/html Connection: keep-alive X-Whom: l1-biz-cyber
Now, sent www.cyberciti.biz as Host header:
$ curl -I -H 'Host: www.cyberciti.biz' 75.126.153.206:80
Sample outputs:
HTTP/1.1 200 OK Server: nginx Date: Wed, 31 Oct 2012 18:52:20 GMT Content-Type: text/html Connection: keep-alive X-Whom: l2-com-cyber Vary: Cookie Last-Modified: Wed, 31 Oct 2012 18:48:58 GMT Cache-Control: max-age=98, must-revalidate X-Galaxy: Andromeda-1 X-Origin-Type: DynamicViaDAL
You can use this command to test Apache server node behind a load balancer (only work with your own VLAN/LAN setup):
## see if 192.168.1.11:95 apache node #1 is working or not ## curl -I --header 'Host: www.cyberciti.biz' 'http://192.168.1.11:95/'
Sample outputs:
HTTP/1.1 200 OK
X-Whom: l1-com-cyber
Vary: Cookie
Last-Modified: Wed, 31 Oct 2012 18:54:00 GMT
Cache-Control: max-age=77, must-revalidate
Content-type: text/html
Date: Wed, 31 Oct 2012 18:57:43 GMT
Server: lighttpd
This option can be used multiple times to add/replace/remove multiple headers:
curl www.cyberciti.biz \ -H "Accept-Language: en" \ -H "Host www.cyberciti.biz" \ -H "User-Agent: curl"
References
See curl command man page for more options:
$ man curl
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 3 comments… read them below or add one }
Plesase correct the url spelling “-sedning”
Thanks for the heads up!
HEDER should be HEADER
:) :)