Mobile phone detection with Varnish – Quick getting started guide

This is a quick reference guide, for a proper understanding of what you are doing use this guide. This solution is easier to implement and has less of a cpu overhead.

yum install libxml2-devel
#OR
apt-get intall libxml2-dev
wget https://gist.github.com/raw/805710/9f34a18e528c20eff1c92672c6f1856ed849f5ea/wurfl.c
wget https://gist.github.com/raw/805710/b9272d8a1d32d29034574c88b81fc79eb050e21b/wurfl.h
gcc -c -o wurfl.o wurfl.c -I/usr/include/libxml2 -fPIC
gcc -shared -Wl,-soname,libwurfl.so.1 -o libwurfl.so.1.0.1 wurfl.o -lxml2
wget http://downloads.sourceforge.net/project/wurfl/WURFL/latest/wurfl-latest.zip
unzip wurfl-latest.zip
mv wurfl.xml /etc/wurfl.xml
cp libwurfl.so /usr/lib
ln -s /usr/lib/libwurfl.so /usr/lib64/libwurfl.so

Edit your /etc/varnish/mobile.vcl using this as a guide

/etc/init.d/varnish stop
/usr/sbin/varnishd -s malloc,32M -a 0.0.0.0:80 -f /etc/varnish/mobile.vcl   -p 'cc_command=exec cc -fpic -shared -Wl,-x -lwurfl -o %o %s'

Test by looking in your server heads.. IE in PHP.. print_r ($_SERVER);

4 thoughts on “Mobile phone detection with Varnish – Quick getting started guide

  1. I think I did try it and it put a huge load on my server when running in production mode.

  2. There at least three other ways to get this done in Varnish:

    A VCL defined device_detection subroutine which is used by many big sites:
    * https://github.com/varnish/varnish-devicedetect/

    A commercial graded product with support from Varnish Software which uses dotMobi’s DeviceAtlas C++ API VMOD:
    * https://www.varnish-cache.org/vmod/deviceatlas-mobile-detection

    A FLOSS version that provides you speed (C API + Java JNI) using the dClass C API VMOD with OpenDDR:
    * https://github.com/TheWeatherChannel/dClass

    Pick and choose the option that suits your needs.

Leave a Reply

Your email address will not be published. Required fields are marked *