87
I Use This!
Moderate Activity

News

Analyzed about 9 hours ago. based on code collected about 10 hours ago.
Posted over 15 years ago
In the tutorial http://varnish-cache.org/wiki/GeoipUsingInlineC, you can see one way to do. But there is another way, with no need to compile a geoip_plugin.so. Follow these steps: Go on http://www.maxmind.com/app/c Download ... [More] http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz Download the last database http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz Install GeoIp: ./configure make make check make install Update your database: GeoIp.dat (/usr/local/share/GeoIP/GeoIP.dat) Edit your /etc/sysconfig/varnish : add : -p 'cc_command=exec cc -fpic -shared -Wl,-x -L/usr/include/libmemcached/memcached.h -L/usr/local/lib -lGeoIP -lmemcached -o %o %s' \ or if you don’t need memcached: -p 'cc_command=exec cc -fpic -shared -Wl,-x -L/usr/local/lib -lGeoIP -o %o %s' \ Add the following lines in your vcl C{ #include <GeoIP.h> static GeoIP *gi = NULL; const char* get_country_code(const char* ip) { const char* country = NULL; if (gi == NULL) gi = GeoIP_new(GEOIP_STANDARD); if (ip != NULL) country = GeoIP_country_code_by_addr(gi, ip); return country ? country : "Unknown"; } }C C{ VRT_SetHdr(sp, HDR_REQ, "\017X-Country-Code:", (*get_country_code)( VRT_IP_string(sp, VRT_r_client_ip(sp)) ), vrt_magic_string_end); }C Now you have the country code in a new header: X-Country-Code [Less]
Posted over 15 years ago
There is a way to add the time taken to serve the request in the varnishncsa logs. You must use the version 2.1.2 of Varnish. Then apply the following patch http://varnish-cache.org/ticket/712 , you can download here. In order to use the new ... [More] option, launch the varnishncsa with the command line: varnishncsa -L "%h %l %u %t \"%{VarnishR}i\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %D" %D refer to “The time taken to serve the request, in microseconds”. Here a list of options: %H, Protocol version %{Host}i %{Referer}i %U, URL path %q, the query string %U%q, URL path and query string %{User-agent}i %{X-Forwarded-For}i %b, Bytes %h (host name / IP adress) %m, Request method %s, Status %t, Date and time %u, Remote user %D, The time taken to serve the request, in microseconds %{X-Cache-Age}i Age of served object I don’t know if the patch is official. Be careful on production, i’ve some segfault: kernel: varnishncsa[29466]: segfault at 0000000000000000 rip 000000368a2797e0 rsp 00007fff0348dbf8 error 4 [Less]