Просмотр исходного кода

use x-forwarded-for in nginx log parse if so desired

Tobias von Dewitz 6 лет назад
Родитель
Сommit
bed5afdb48
1 измененных файлов с 12 добавлено и 0 удалено
  1. 12 0
      main.go

+ 12 - 0
main.go

@@ -278,6 +278,18 @@ func nginxLogCapture(logfile, format string) {
 			continue
 		}
 
+		if *useXForwardedAsSource {
+			xff, err := logEntry.Field("http_x_forwarded_for")
+			if err != nil {
+				remote = xff
+			}
+		}
+
+		if remote == "" {
+			log.Println("remote is empty: ignoring request.")
+			continue
+		}
+
 		// only use the first host in case there are multiple hosts in the log
 		if cidx := strings.Index(remote, ","); cidx >= 0 {
 			remote = remote[0:cidx]