Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教下,模块有哪些 Variables,想写到 access log #2

Open
peytonyip opened this issue Apr 4, 2021 · 2 comments
Open

请教下,模块有哪些 Variables,想写到 access log #2

peytonyip opened this issue Apr 4, 2021 · 2 comments

Comments

@peytonyip
Copy link

尝试把模块编译进 nginx 了,目前的配置:
main 块:

load_module modules/ngx_ip2region_module.so;

ip2region_db_file /path/to/ip2region.db;
ip2region_algo btree;

目前想把解析 ip 记录到access log,类似 https://github.com/ip2location/ip2location-nginx/blob/master/README.md#variables
看了下源码,貌似没有找到相关的变量值,可否增加一下呢,谢谢!

@Cherisher
Copy link
Owner

你可以描述一下具体需要哪些?看库里面是否有变量可以导出

@peytonyip
Copy link
Author

peytonyip commented Apr 8, 2021

现在用的 ngx_http_geoip2_module 这个模块,用了其中两个变量,一个是记录 ip 的国家,一个是 ip 的城市,便于用 grafana 统计展示访问来源

http 配置如下

log_format acess-log escape=json
...
'"geoip2_data_country_code": "$geoip2_data_country_code",'
 '"geoip2_data_city_name": "$geoip2_data_city_name"'
...

日志样例:

"geoip2_data_country_code": "CN","geoip2_data_city_name": "Guangzhou"

ip2region 的数据相对准确,因此想使用这个模块给 nginx 解析 ip 来源,记录到日志文件,达到上面的结果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants