Understanding GeoIP module source?
de_nginx_noob
nginx-forum at nginx.us
Tue Oct 20 19:48:09 UTC 2015
Unforunately, I got assigned the task of writing a module that takes the the
IP address of every http request's client and running some proprietary
algorithm to determine to generate geolocation data (similar to Maxmind, but
more detailed). I was told to use the geoip module as a base for my custom
code. Admittedly, I have very little experience in C, but that's not the
issue here. The issue is the lack of documentation.
I've spent all day trying to understand the source code located here :
http://lxr.nginx.org/source/src/http/modules/ngx_http_geoip_module.c
I've also been using this guide as a reference :
http://www.evanmiller.org/nginx-modules-guide.html#components.
No one in my office knows how nginx modules work.
I think that this array holds the data :
static ngx_http_variable_t ngx_http_geoip_vars[]
But I'm confused on how that data gets set? How does it get returned as
variables to be used in the nginx.conf file?
This function here seems to handle a request :
static u_long
ngx_http_geoip_addr(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf)
{
But I don't understand how it it works in conjunction with the array above.
I don't understand how where to even begin? I need this module to run in the
http context for every http connection. Each time it runs, I'm supposed to
get the client's ip address and do some proprietary stuff and more
importantly, return certain values similar to how the geoip module does for
these directives :
geoip_country
geoip_city
geoip_org
Please help. I'm completely stuck.
Thanks everyone.
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,262383,262383#msg-262383
More information about the nginx
mailing list