Nginx网站架构实战——04、nginx日志管理

前言:

Nginx网站架构实战——01、Nginx介绍及编译安装:传送门

Nginx网站架构实战——02、Nginx信号量:传送门

Nginx网站架构实战——03、nginx虚拟主机配置:传送门

Nginx日志格式

[root@tiejiang nginx]# vim conf/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"';
    
注释
    远程IP- 远程用户/用户时间 请求方法(如GET/POST) 请求体body长度 referer来源信息 http-user-agent用户代理/蜘蛛 ,被转发的请求的原始IP
    
    192.168.0.102 - - [13/May/2018:20:54:33 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER"

开启z.com的网站访问日志

[root@tiejiang nginx]# vim conf/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"';

然后给网站设置日志的格式
    server {
        listen 80;
        server_name z.com;

        location / {
            root z.com;
            index index.html;
        }
        access_log logs/z.com.access.log main;      #设置z.com的log名称及日志格式
    }
    
[root@tiejiang nginx]# ./sbin/nginx -s reload
[root@tiejiang nginx]# ls logs/             #目录下就有一个z.com.access.log的文件
    access.log  access.log.20180513  error.log  nginx.pid  z.com.access.log
[root@tiejiang nginx]# tail -1 logs/z.com.access.log 
    192.168.0.102 - - [13/May/2018:23:39:53 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" "-"
    远程IP- 远程用户/用户时间 请求方法(如GET/POST) 请求体body长度 referer来源信息 http-user-agent用户代理/蜘蛛 ,被转发的请求的原始IP

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/54286.html

(0)
上一篇 2021年8月7日 02:17
下一篇 2021年8月7日 02:17

相关推荐

发表回复

登录后才能评论