码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 访问日志

时间:2019-01-29 12:00:47      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:bmp   日志格式   访问时间   网址链接   服务器ip   nbsp   agent   链接   request   

配置访问日志:

[root@localhost ~]$ cat /usr/local/nginx/conf/nginx.conf

http {    

    log_format  main  $remote_addr - $remote_user [$time_local] "$request"     # 定义日志格式,main是日志格式的名称,以便后面调用
                      $status $body_bytes_sent "$http_referer"                 
                      "$http_user_agent" $http_x_forwarded_for;

    access_log  /data/nginx_logs/access.log  main;    # 指定访问日志的存放路径及使用哪个日志格式来记录日志
}

可以指定静态文件被访问时不记录日志:

[root@localhost ~]$ cat /usr/local/nginx/conf/vhost/test.com.conf 
server {
    listen 80;
    server_name www.test.com;
    index index.html index.html index.php;
    root /data/www;
  
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
        access_log off;
    }
}

 

变量 含义
$remote_addr 客户端IP
$remote_user 客户端用户
$time_local 服务器本地时间,也就是客户端访问时间
$request 客户端请求的URL
$status 请求的状态码
$body_bytes_sent 发送给客户端的字节数
$http_referer 从哪个网址链接过来
$http_user_agent 使用哪个浏览器访问
$http_x_forwarded_for 代理服务器IP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

     

Nginx 访问日志

标签:bmp   日志格式   访问时间   网址链接   服务器ip   nbsp   agent   链接   request   

原文地址:https://www.cnblogs.com/pzk7788/p/10333032.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!