Linux10.6 Nginx访问日志

日志格式

vim /usr/local/nginx/conf/nginx.conf //搜索log_format

$remote_addr客户端IP(公网IP)
$http_x_forwarded_for代理服务器的IP
$time_local服务器本地时间
$host访问主机名(域名)
$request_uri访问的url地址
$status状态码
$http_refererreferer
$http_user_agentuser_agent
主配置文件配置格式名为 combined_realip 格式的访问日志
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    ' $host "$request_uri" $status'
    ' "$http_referer" "$http_user_agent"';


除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中server块中增加,后面的combined_realip为日志格式名字,在主配置文件中配置

 access_log /tmp/1.log combined_realip;

 这里的combined_realip就是在nginx.conf中定义的日志格式名字
 -t && -s reload
 curl -x127.0.0.1:80 test.com -I
 cat /tmp/1.log