自定义 nginx 日志格式

创建日期: 2023-03-24 13:56 | 作者: 风波 | 浏览次数: 19 | 分类: Nginx

日志格式定义

日志格式需要定义在 http 段中,而不是 server 段中。

    log_format  main  '$remote_addr $remote_port - [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

这个日志格式的名字就叫做 main

日志格式的使用

日志使用域可以是 httpserverlocation

access_log /var/log/nginx/access.log main;

这个就是指定使用 main 格式的日志。


参考: - https://www.jianshu.com/p/ad4e8038bf8b - https://blog.51cto.com/john88wang/1672876

19 浏览
15 爬虫
0 评论