ScaleScaleScaleScale

Tips / Nginx


Varnish: change server name response

Varnish

Varnish is a web cache server, that can help you to reduce the load of your server, and at the same time will improve your websites speed. I’ve been playing with this software since about 1 year ago, and even I don’t still pretty confortable with it, I have to admit that  it is very powerful if you know how to use it. Today I will share a simple tip for Varnish users, and that is how to change the Varnish server name response in the server headers.

Note: this tutorial only works  on Varnish 3.x

First, let’s install Varnish

Install Varnish

On Ubuntu/Debian:

apt-get install varnish

On CentOS/RHEL:

yum install -y gcc make automake autoconf libtool ncurses-devel libxslt groff pcre-devel pckgconfig libedit libedit-devel
rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-4.0.el6.rpm
yum install varnish

CentOS users: if that doens’t work you may want to check this out: How to install Varnish on CentOS

On Fedora:

yum install -y gcc make automake autoconf libtool ncurses-devel libxslt groff pcre-devel pckgconfig libedit libedit-devel
yum install varnish

Change/hide Varnish server name

Edit the .vlc file you are using, in my case it was default.vlc:

nano -w /etc/varnish/default.vcl

On the sub vcl_deliver section, replace all the content with this lines:

sub vcl_deliver {
remove resp.http.Via;
remove resp.http.X-Whatever;
remove resp.http.X-Powered-By;
remove resp.http.X-Varnish;
remove resp.http.Age;
remove resp.http.Server;
set resp.http.Server = "Nginxtips.com";
set resp.http.X-Powered-By = "NginxTips.com Web Server";
}

To apply changes just restart Varnish

/etc/init.d/varnish restart

Test Varnish header response

We will use curl to get the headers and see if our server name change work or not. On this test I had Nginx server running on port 80, which delivered a 403 Forbidden status (normal because I had no index files) and Varnish at the default port listening on 6081 after a fresh installation:

[root@localhost ~]# curl -I 127.0.0.1:6081
HTTP/1.1 403 Forbidden
Last-Modified: Wed, 23 Jul 2014 10:24:04 GMT
ETag: "1201-4fed9bd4ad900"
Accept-Ranges: bytes
Content-Type: text/html; charset=UTF-8
Content-Length: 4609
Accept-Ranges: bytes
Date: Mon, 25 Aug 2014 11:10:51 GMT
Connection: keep-alive
Server: Nginxtips.com
X-Powered-By: NginxTips.com Web Server

As you see the header is showing:

Server: Nginxtips.com
X-Powered-By: NginxTips.com Web Server

Popular search terms:

  • resp http * varnish
  • varnish get the server name
  • varnish server rsponse time
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Adithya

    Varnish 4 fails to compile after adding the lines

    Please help

    • admin

      You are right, this only seems to be working on the 3.x versions, I just verified that.
      Remove the lines for now, I’ll find a way to apply the same changes on Varnish 4.x