启用CDN后Nginx日志显示真实的用户IP的方法

87 阅读技术资料nginx
0

修改 Nginx 配置文件 /usr/local/nginx/conf/nginx.conf 文件,添加在 http 字段中:

map $HTTP_CF_CONNECTING_IP  $clientRealIp {
    ""    $remote_addr;
    ~^(?P<firstAddr>[0-9.]+),?.*$    $firstAddr;
}
log_format  main  '$clientRealIp [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '$http_user_agent $remote_addr $request_time';

然后在网站记录的日志定义使用main这个日志格式:

access_log /data/wwwlogs/manage.qyfou.com_nginx.log main;

分享到:
提问于

Login

Welcome! Login in to your account

Remember meLost your password?

Don't have account. Register

Lost Password

Register