美文网首页
Golang+Nginx实现日志打点

Golang+Nginx实现日志打点

作者: Y了个J | 来源:发表于2022-04-12 22:45 被阅读0次

    准备nginx环境

    修改nginx.conf然后 nginx -s reload

    
    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        server {
            listen       8080;
            server_name  localhost;
    
            # 开启 access_log,后面解析这个日志文件,log_format 注释也打开
            access_log  logs/host.access.log  main;
    
            # 打点地址,单向流程不需要返回什么,empty_gif 只有200多B,很小
            location /dig {
                empty_gif;
                # nginx不允许用POST方式请求静态资源,下面可以支持POST请求
                error_page 405 =200 $request_uri;  
            }
    
    ......
    

    go程序流程

    70491649775504_.pic_hd.jpg

    相关文章

      网友评论

          本文标题:Golang+Nginx实现日志打点

          本文链接:https://www.haomeiwen.com/subject/bdqosrtx.html