配置访问日志:

[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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

     

相关文章:

  • 2021-08-20
  • 2021-09-11
  • 2018-07-15
  • 2019-10-12
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-08-10
  • 2021-04-17
  • 2021-04-03
  • 2021-07-24
相关资源
相似解决方案