宝塔面板nginx更改日志格式的方法
宝塔默认的日志格式比较简单,可能有些站长需要自定义日志格式,而不知道从何下手,其实这个就是简单的定义nginx的过程
只是宝塔的nginx配置文件存放位置与一般nginx不一样
宝塔存放nginx配置文件位置:/www/server/nginx/conf/nginx.conf
一般nginx的配置文件位置:/usr/local/nginx/conf/nginx.conf
增加自定义格式只需要在
http
{
...
}这里面增加:
log_format main '$http_x_forwarded_for [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '$http_user_agent $remote_addr $request_time';

然后在网站部分的日志文件后面加个main标志
比如
access_log /www/wwwlogs/www.bnxb.com.log main;


支持的参数如下:
参数 说明 示例$remote_addr 客户端地址 211.28.65.253$remote_user 客户端用户名称 --$time_local 访问时间和时区 18/Jul/2012:17:00:01 +0800$request 请求的URI和HTTP协议 "GET /article-10000.html HTTP/1.1"$http_host 请求地址,即浏览器中你输入的地址(IP或域名) www.bnxb.com 192.168.100.100$status HTTP请求状态 200$upstream_status upstream状态 200$body_bytes_sent 发送给客户端文件内容大小 1547$http_referer url跳转来源 https://cdn.bnxb.com/$http_user_agent 用户终端浏览器等信息 "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; GTB7.0; .NET4.0C;$ssl_protocol SSL协议版本 TLSv1$ssl_cipher 交换数据中的算法 RC4-SHA$upstream_addr 后台upstream的地址,即真正提供服务的主机地址 10.10.10.100:80$request_time 整个请求的总时间 0.205$upstream_response_time 请求过程中,upstream响应时间 0.002也可以这样操作,用于套了CDN的网站识别访客的真实IP
在http部分
include proxy.conf;下面增加
map $http_x_forwarded_for $clientRealIp
{
"" $remote_addr;
~^(?P<firstAddr>[0-9.]+),?.*$ $firstAddr;
}然后日志格式用
log_format main '$clientRealIp [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '$http_user_agent $remote_addr $request_time';
顶(5)
踩(0)
- 最新评论
