nginx.conf文件配置:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
#日志生成的到Nginx根目录/var/log/nginx/access.log文件,默认使用“main”日志格式,也可以自定义格式。
参数明细表:
$remote_addr | 客户端的ip地址(代理服务器,显示代理服务ip) |
$remote_user | 用于记录远程客户端的用户名称(一般为“-”) |
$time_local | 用于记录访问时间和时区 |
$request | 用于记录请求的url以及请求方法 |
$status | 响应状态码,例如:200成功、404页面找不到等。 |
$body_bytes_sent | 给客户端发送的文件主体内容字节数 |
$http_user_agent | 用户所使用的代理(一般为浏览器) |
$http_x_forwarded_for | 可以记录客户端IP,通过代理服务器来记录客户端的ip地址 |
$http_referer | 可以记录用户是从哪个链接访问过来的 |