diff --git a/binding/nginx/README.md b/binding/nginx/README.md index 15c2ec28005e0eadb4b67108e25676c5169d2ac8..be91805ff56a5382294bf856454358ca0cedc53d 100644 --- a/binding/nginx/README.md +++ b/binding/nginx/README.md @@ -4,11 +4,39 @@ ```shell $ ./configure \ - --prefix=/Users/wujp/Documents/workspaces/open-source/nginx-1.23.4/.nginx \ - --add-module=/Users/wujp/Documents/workspaces/open-source/ip2region/binding/nginx + --prefix=$(PWD)/../build \ + --add-module=$(PWD)/../ip2region/binding/nginx $ make $ make install ``` +```nginx +... +http { + + log_format json_access_log escape=json '{' + '"remote_addr": "$remote_addr", ' + '"region": "$ip2region", ' + '"http_x_forwarded_for": "$http_x_forwarded_for"' + '}'; + + access_log logs/access.log json_access_log; + + # 设置xdb文件路径 + ip2region ip2region.xdb; + + server { + listen 80; + server_name localhost; + + location / { + root html; + index index.html index.htm; + } + } +} + +``` + Made with ♥ by Wu Jian Ping diff --git a/binding/nginx/src/ngx_http_ip2region_module.c b/binding/nginx/src/ngx_http_ip2region_module.c index ac148f3184dc310e421cfc5443bf5aefa3bca6ca..37950061be420e964c1ef8327b3f683a6642e5c7 100644 --- a/binding/nginx/src/ngx_http_ip2region_module.c +++ b/binding/nginx/src/ngx_http_ip2region_module.c @@ -10,7 +10,7 @@ static ngx_int_t ngx_http_ip2region_add_variables(ngx_conf_t *cf); static void *ngx_http_ip2region_create_conf(ngx_conf_t *cf); static void ngx_http_ip2region_cleanup(void *data); -static char *ngx_http_ip2region_processor(ngx_conf_t *cf, +static char *ngx_http_ip2region_init(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_int_t ngx_http_ip2region_variable(ngx_http_request_t *r, @@ -31,7 +31,7 @@ static ngx_http_module_t ngx_http_ip2region_ctx = { static ngx_command_t ngx_http_ip2region_commands[] = { { ngx_string("ip2region"), NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE12, - ngx_http_ip2region_processor, + ngx_http_ip2region_init, NGX_HTTP_MAIN_CONF_OFFSET, 0, NULL }, @@ -67,7 +67,7 @@ static ngx_http_variable_t ngx_http_ip2region_vars[] = { static char * -ngx_http_ip2region_processor(ngx_conf_t *cf, ngx_command_t *cmd, +ngx_http_ip2region_init(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_ip2region_conf_t *ip2region_cf;