How to Customize Server Header using NginX headers-more module

Valic —  March 4, 2013 — 1 Comment

When you are browsing a website, you can check the type of web server running by retrieving the response server header. For example the following server response return for website http://www.debian-tutorials.com:

HTTP/1.1 200 OK
Server: Apache/2.2.22
Date: Mon, 04 Mar 2013 00:43:59 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.2.17
X-Pingback: http://www.debian-tutorials.com/xmlrpc.php
Cache-Control: max-age=7200
Expires: Mon, 04 Mar 2013 02:43:58 GMT
Vary: Accept-Encoding

From the information we can know that the web server is running on Apache version 2.2.22.

By using NginX you can personalize and customize your server header to the name that you want. Instead of showing the real web server name which is “nginx“  you can set for users to see the web server name as “my websites webserver“.

In this guide I will show you how to  customize server header using NginX headers-more module without compiling again the server.

1. Install Nginx webserver if you don’t have it installed already.

You can use this guide to do it: Setting up Nginx plus PHP FastCGI on Debian 6.0.6 Squeeze

2.Install nginx-extras package.

In Debian Squeeze exists one package called nginx-extras that contains some standard modules, plus extra features and modules like headers-more-module and others. You can find more info here: http://packages.debian.org/sid/nginx-extras

Install the nginx-extras packages like this:

apt-get install nginx-extras

3. Make some changes under  http directive to NginX configuration file which located under /etc/nginx/nginx.conf as below:

http {
#This is your web server name
more_set_headers "Server: Debian-Tutorials.com Web Server";

# Let NGINX get the real client IP for its access logs
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;

## Default log and error files.
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

Before you restart the NginX, make sure you check the configuration syntax:

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If everything is okay you can restart the web server now:

/etc/init.d/nginx restart
[ ok ] Restarting nginx: nginx.

Now you can check the server header and you will notice that your customize web server name has appeared at the “Server” section.

HTTP/1.1 200 OK
Server: Debian-Tutorials.com Web Server
Date: Mon, 04 Mar 2013 00:43:59 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.2.17
X-Pingback: http://www.debian-tutorials.com/xmlrpc.php
Cache-Control: max-age=7200
Expires: Mon, 04 Mar 2013 02:43:58 GMT
Vary: Accept-Encoding

You can optionally add the following lines into NginX configuration file:

more_clear_headers   "Content-Type: ";
more_clear_headers   "Accept-Ranges: ";
more_clear_headers   "Content-Length: ";

After NginX restart, the full server header will be returned as below:

HTTP/1.1 200 OK
Date: Mon, 04 Mar 2013 01:15:32 GMT
Last-Modified: Tue, 26 Feb 2013 17:54:58 GMT
Connection: keep-alive
Keep-Alive: timeout=10
Server: Debian-Tutorials.com Web Server

For more information about more-headers you can check this page: http://wiki.nginx.org/HttpHeadersMoreModule

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

One response to How to Customize Server Header using NginX headers-more module

  1. Thanks!. Was searching how to change the server header, works like a charm!

Leave a Reply