1,配置http_geoip_module模块。https://abc.htmltoo.com/thread-568.htm
2,修改nginx配置文件nginx.conf
配置参数如下:
log_format main '$remote_addr[$geoip_country_code] - $remote_user [$upstream_addr] [$upstream_response_time] [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$http_accept_language"';
access_log /logs/nginx/access.log main;
geoip_country /usr/local/share/GeoIP/GeoIP.dat;
重启nginx:
/usr/local/nginx/sbin/nginx -s reload
查看最后一行访问日志:
[root@21yunwei ~]# tail -1 /logs/nginx/access.log
121.88.22.15[CN] - - [-] [-] [17/Feb/2017:13:18:52 +0800] "GET /favicon.ico HTTP/1.1" 304 0 "http://test.21yunwei.com/1.php" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36" "-" "zh-CN,zh;q=0.8"
国家代码判断成功。
3,强判断代码加入到php变量中。
修改nginx配置目录下的fastcgi_params 文件,设置添加参数:
fastcgi_param COUNTRY_CODE "$geoip_country_code";
fastcgi_param HTTP_COUNTRY_CODE "$geoip_country_code";
重启nginx加载服务后查看php 变量.
签名:这个人很懒,什么也没有留下!