Browse Source

split x-forwarded-for ips in nginx log

Tobias von Dewitz 6 years ago
parent
commit
3dc8bcb3c9
1 changed files with 4 additions and 1 deletions
  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])
+				}
 			}
 		}