<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ## 配置指令 1、在kong.conf中增加如下配置: ``` nginx_http_log_format=main '$remote_addr $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" $http_user_agent $http_x_forwarded_for $request_time $upstream_response_time $upstream_addr $upstream_status' ``` 2、在kong.conf中修改proxy_access_log為: ``` proxy_access_log = logs/access.log main ``` 3、最終配置結果為: ![](https://img.kancloud.cn/8f/71/8f718afe5abb9a48d01286a23f23cb30_1295x317.png) 4、重啟kong后,查看nginx-kong.conf文件,會看到注入指令相關信息: ![](https://img.kancloud.cn/2f/5a/2f5aed3ebd37cf50aec1f9a29ba1fdbd_1291x498.png) server 模塊中: ![](https://img.kancloud.cn/e4/2c/e42c488544358e84703f499fb026f975_712x326.png) ## 結果驗證 ``` 192.168.66.144 - [14/Jan/2021:17:49:27 +0800] "GET /request HTTP/1.1" 401 26 "-" curl/7.29.0 - 0.003 - - - 192.168.66.144 - [14/Jan/2021:17:49:32 +0800] "GET /request HTTP/1.1" 401 26 "-" curl/7.29.0 - 0.003 - - - ``` 對比一下是否和上面配置的format是一致的呢?一致說明配置生效了。日志中的`-`其實對應的是沒有數據,所以最后連續的三個`-`對應`$upstream_response_time $upstream_addr $upstream_status`,這三個變量沒有值,為什么? 因為format格式中使用的變量其實是nginx http,upstream,log等模塊提供的,具體有什么變量可用,可查閱[官方文檔](http://nginx.org/en/docs/http/ngx_http_core_module.html)。由于我這里使用Kong作為一個簡單的請求代理,并未使用upstream模塊來做對上游服務的度負載均衡,所以所有`$upstream`開頭的變量是沒有值的。 基于此應當明白,這樣的配置日志格式,僅僅是使用了nginx提供的功能,這里的配置與使用Kong的日志插件沒有關系。此種方式也并不能使用openresty和kong提供的變量,比如獲取請求處理過程中的延遲情況。所以這種方式的日志能提供的信息很少,**要想獲取更加全面的日志信息,應當使用日志插件**。 ## 自定義變量 前面提到,nginx內置變量固定,log中只能記錄nginx變量,但是我們可以自定義變量,在請求處理過程中寫入值,然后配置log\_format輸出。假設我現在想要記錄token里的clientid,應該怎么做呢? 1. 使用set指令自定義一個變量client\_id,默認值為空字符,即在kong.conf文件中增加如下配置:`nginx_proxy_set=$client_id ''` 2. 在jwt插件中解析token后,取到clientid的值并寫入變量:`ngx.var.client_id = kong.ctx.plugin.client_id` 3. 修改log\_format :`nginx_http_log_format=main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time "$http_authorization" "$client_id" '`
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看