Akins, Brian
December 20, 2010 01:38PM
Corrected patch below...


On 12/20/10 1:29 PM, "Brian Akins" <Brian.Akins@turner.com> wrote:

> The attached patch allows you to change the geoip cache option in the
> config. For example:
>
> geoip_country /usr/share/GeoIP/GeoIP.dat mmap;
>
> Will use GEOIP_MMAP_CACHE. The default is memory ( GEOIP_MEMORY_CACHE ),
> the same as today. The mmap option can make a large difference in memory
> usage when using the large city data files.
>
>
> --
> Brian Akins
>
--- nginx-0.8.54/src/http/modules/ngx_http_geoip_module.c 2010-08-03
14:38:08.000000000 -0400
+++ nginx-0.8.54.geoip/src/http/modules/ngx_http_geoip_module.c 2010-12-20
13:17:10.000000000 -0500
@@ -50,14 +50,14 @@
static ngx_command_t ngx_http_geoip_commands[] = {

{ ngx_string("geoip_country"),
- NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE12,
ngx_http_geoip_country,
NGX_HTTP_MAIN_CONF_OFFSET,
0,
NULL },

{ ngx_string("geoip_city"),
- NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE12,
ngx_http_geoip_city,
NGX_HTTP_MAIN_CONF_OFFSET,
0,
@@ -423,11 +423,29 @@
return conf;
}

+static ngx_int_t ngx_http_geoip_cache_type(ngx_str_t *value)
+{
+ ngx_int_t cache = GEOIP_MEMORY_CACHE;
+
+ if(!ngx_strncasecmp(value->data, (u_char *)"MEMORY", value->len)) {
+ cache = GEOIP_MEMORY_CACHE;
+ } else if(!ngx_strncasecmp(value->data, (u_char *)"CHECK", value->len))
{
+ cache = GEOIP_CHECK_CACHE;
+ } else if(!ngx_strncasecmp(value->data, (u_char *)"INDEX", value->len))
{
+ cache = GEOIP_INDEX_CACHE;
+ } else if(!ngx_strncasecmp(value->data, (u_char *)"MMAP", value->len))
{
+ cache = GEOIP_MMAP_CACHE;
+ } else {
+ return NGX_CONF_ERROR;
+ }
+ return cache;
+}

static char *
ngx_http_geoip_country(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_geoip_conf_t *gcf = conf;
+ ngx_int_t cache = GEOIP_MEMORY_CACHE;

ngx_str_t *value;

@@ -437,7 +455,15 @@

value = cf->args->elts;

- gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
+ if(cf->args->nelts == 3) {
+ if((cache = ngx_http_geoip_cache_type(&value[2])) ==
NGX_CONF_ERROR) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "Unknown GeoIP cache type: \"%V\"",
&value[2]);
+ return NGX_CONF_ERROR;
+ }
+ }
+
+ gcf->country = GeoIP_open((char *) value[1].data, cache);

if (gcf->country == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@@ -467,6 +493,7 @@
ngx_http_geoip_city(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_geoip_conf_t *gcf = conf;
+ ngx_int_t cache = GEOIP_MEMORY_CACHE;

ngx_str_t *value;

@@ -476,7 +503,15 @@

value = cf->args->elts;

- gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
+ if(cf->args->nelts == 3) {
+ if((cache = ngx_http_geoip_cache_type(&value[2])) ==
NGX_CONF_ERROR) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "Unknown GeoIP cache type: \"%V\"",
&value[2]);
+ return NGX_CONF_ERROR;
+ }
+ }
+
+ gcf->city = GeoIP_open((char *) value[1].data, cache);

if (gcf->city == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Geoip cache options patch Attachments

Akins, Brian 3010 December 20, 2010 01:30PM

Re: Geoip cache options patch

Akins, Brian 1097 December 20, 2010 01:38PM

Re: Geoip cache options patch

Igor Sysoev 1115 December 20, 2010 01:42PM

Re: Geoip cache options patch

Igor Sysoev 1126 December 20, 2010 02:00PM

Re: Geoip cache options patch

Akins, Brian 963 December 20, 2010 05:46PM

Re: Geoip cache options patch

Eugaia 1023 December 20, 2010 05:58PM

Re: Geoip cache options patch

Akins, Brian 985 December 20, 2010 06:26PM

Re: Geoip cache options patch

Eugaia 1046 December 20, 2010 07:42PM

Re: Geoip cache options patch

Igor Sysoev 1074 December 21, 2010 07:28AM

Re: Geoip cache options patch

Akins, Brian 1337 December 21, 2010 09:20AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 192
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready