NGINX 中文日誌十六進制編碼問題

Nginx訪問日誌在處理中文時,默認使用16進制編碼處理。使我們對訪問日誌進行分析處理時,帶來很大不便。含有中文字符的請求,日誌記錄如下:

171.43.238.62 - - [05/Dec/2017:21:40:57 +0800] "GET /\xD6\xD0\xCE\xC4 HTTP/1.1" 404 171 "-" "curl/7.56.0"

問題解決方案:

  1. nginx版本需大於1.11.8
  2. 在定義 access log 格式時,加上 escape=json

日誌格式示例:

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

結果:

47.52.167.143 -  [05/Dec/2017:21:55:59 +0800] "GET /中文 HTTP/1.1" 404 171 "" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2" ""
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章