瀏覽代碼

split x-forwarded-for ips in nginx log

Tobias von Dewitz 6 年之前
父節點
當前提交
3dc8bcb3c9
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      main.go

+ 4 - 1
main.go

@@ -281,7 +281,10 @@ func nginxLogCapture(logfile, format string) {
 		if config.UseXForwardedAsSource {
 			xff, err := logEntry.Field("http_x_forwarded_for")
 			if err != nil && xff != "" {
-				remote = xff
+				ips := strings.Split(xff, ",")
+				if len(ips) > 0 {
+					remote = strings.TrimSpace(ips[0])
+				}
 			}
 		}