日志格式设置:
$remote_addr与$http_x_forwarded_for用以记录客户端的ip地址;
$remote_user:用来记录客户端用户名称;
$time_local: 用来记录访问时间与时区;
$request: 用来记录请求的url与http协议;
$status: 用来记录请求状态;成功是200,
$body_bytes_sent :记录发送给客户端文件主体内容大小;
$http_referer:用来记录从那个页面链接访问过来的;
$http_user_agent:记录客户浏览器的相关信息
$remote_user:用来记录客户端用户名称;
$time_local: 用来记录访问时间与时区;
$request: 用来记录请求的url与http协议;
$status: 用来记录请求状态;成功是200,
$body_bytes_sent :记录发送给客户端文件主体内容大小;
$http_referer:用来记录从那个页面链接访问过来的;
$http_user_agent:记录客户浏览器的相关信息
在http里面加以下,mylogformat两边不能有空格,本人设置时有空格报错
log_format mylogformat '$remote_addr - $http_x_forwarded_for - $remote_user - [$time_local] - $request - $status - $body_bytes_sent - $http_referer - $http_user_agent';
server里需要指定 定义的日志
access_log /home/wwwlogs/access.log my_format;
配置片段
http { include mime.types; default_type application/octet-stream; log_format mylogformat '$remote_addr - $http_x_forwarded_for - $remote_user - [$time_local] - $request - $status - $body_bytes_sent - $http_referer - $http_user_agent'; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 100m; sendfile on; tcp_nopush on; ....... server {....... access_log /home/wwwlogs/access.log my_format; .......
重启nginx后用tail -f 查看日志