Ngin日志日志格式

Nginx的日志配置在/usr/local/nginx/conf/nginx.con配置文件中

 

http {
    include       mime.types;
    default_type  application/octet-stream;

     log_format main ' "$remote_addr" "$upstream_addr" "[$time_local]" "$request_time" "$upstream_response_time" "$status" "$sent_http_error_code" "$content_length""$body_bytes_sent" "$http_request_id" "$request" "$http_user_agent" "$http_host" "$server_addr"';


   access_log  logs/access.log  main;

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

 

 

其中注释的内容为默认的配置:

       1.$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;
        2.$remote_user :用来记录客户端用户名称;
        3.$time_local : 用来记录访问时间与时区;
        4.$request : 用来记录请求的url与http协议;
        5.$status : 用来记录请求状态;成功是200,
        6.$body_bytes_s ent :记录发送给客户端文件主体内容大小;
        7.$http_referer :用来记录从那个页面链接访问过来的;
        8.$http_user_agent :记录客户端浏览器的相关信息;

 

其中:access_log  logs/access.log  main; 为日志的路径及文件名在以nginx为根目录的相对路径

 

 

 

未注释的是自定义的配置

"$remote_addr"             :客户端IP地址
"$upstream_addr"           :服务端代理的IP的IP的地址
"[$time_local]"            :当前时间
"$request_time"            :请求时间
"$upstream_response_time"  :响应时间
"$status"                  :响应状态值
"$sent_http_error_code"    :错误的状态值
"$content_length"          :请求的内容的length
"$body_bytes_sent"         : 
"$http_request_id"         : "-" 
"$request"                 :请求头信息  
"$http_user_agent"         :-
"$http_host"               :请求的域名
"$server_addr"';           :Nginx的IP地址

 

输出的例子:

"172.28.6.131" "172.28.6.133:8081" "[25/May/2015:14:05:04 +0800]" "0.004" "0.004" "200" "-" "308""342" "-" "POST /remoting/xxxxServiceCall HTTP/1.1" "-" "rpc.xxx.test.com" "172.28.6.120"

 

配置如下:

 

   upstream rpc.xxx.systoon.com{
       server 172.38.6.135:8081;
       server 172.38.6.136:8081;
       server 172.38.6.137:8081;
    }

server {
        listen 80;
        server_name rpc.xxx.systoon.com;

        location / {
            proxy_pass http://rpc.xxx.systoon.com;
            proxy_set_header Host             $host;
            proxy_set_header X-Real_IP        $remote_addr;
            proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
          }
       }

 在/etc/hosts文件中配置域名Ip地址映射例如:

127.0.0.1   localhost 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值