WebFaction
Community site: login faq

I've been trying to do this for weeks and I just discovered how. To bring anyone reading this randomly up to speed, GeoIP is a system which translates IP addresses to countries, cities, ISPs and/or businesses. This can be done at the web server, CGI/WSGI handler, or application code level. It requires a local database which the information is read from.

mod_geoip2 for Apache by default reads the database from disk when GeoIP is used for a location lookup. If your app uses lots of GeoIP lookups you can cache this database to RAM for each worker so it can make fast lookups without reading from disk. http_geoip_module for Nginx however does not offer any config options for caching and by default loads the databases into RAM for each worker process. This can be a problem if you compile your own Nginx server from source on Webfaction and want GeoIP for very infrequent GeoIP lookups from your analytics software. It inflates the Nginx worker process size to over 20MB each, from the ~700KB or so they are by default. That's a massive increase when your RAM is limited.

So if you'd like to run Nginx with GeoIP support but not cache the GeoIP database into RAM, do the following in the Nginx source code:

  1. Open up src/http/modules/ngx_http_geoip_module.c
  2. Do a find for GEOIP_MEMORY_CACHE
  3. Replace all instances with GEOIP_STANDARD
  4. Recompile Nginx with --with-http_geoip_module
  5. Add GeoIP lines to Nginx config

Now you'll have Nginx running without the GeoIP database being cached by each worker process but GeoIP will still work. It will come at a performance hit though when a web app does a GeoIP lookup. If you're on a 512MB plan and want GeoIP for infrequent lookups this will free up tons of RAM.

I hope this helps some people who, like me, wanted GeoIP support in a custom compiled Nginx install on Webfaction without inflating the memory usage of Nginx by an order of magnitude.

asked 08 Feb '14, 23:30

HittingSmoke
4822230
accept rate: 8%

edited 08 Feb '14, 23:35


Thanks for posting your results.

permanent link

answered 09 Feb '14, 05:27

johns
5.4k412
accept rate: 23%

FYI to anyone using uWSGI. The developer added an undocumented option to the master branch. --geoip-use-disk will prevent the GeoIP database from being cached to RAM. Very useful if you're using Django or web2py with GeoIP.

permanent link

answered 30 Jun '14, 23:17

HittingSmoke
4822230
accept rate: 8%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×186
×10

question asked: 08 Feb '14, 23:30

question was seen: 4,062 times

last updated: 30 Jun '14, 23:17

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM