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

3.06K 浏览技术资料
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;

分享到:
Qi 问的问题 2020年9月28日
添加评论
写下您的答案。

Login

Welcome! Login in to your account

Remember me Lost your password?

Don't have account. Register

Lost Password

Register