소스 검색

use cloudflare ip

Tobias von Dewitz 5 년 전
부모
커밋
f7fc968d86
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      setup.go

+ 4 - 1
setup.go

@@ -146,7 +146,10 @@ func getClientIP(r *http.Request, strict bool) (net.IP, error) {
 	var ip string
 
 	// Use the client ip from the 'X-Forwarded-For' header, if available.
-	if fwdFor := r.Header.Get("X-Forwarded-For"); fwdFor != "" && !strict {
+	if fwdFor := r.Header.Get("CF-Connecting-IP"); fwdFor != "" && !strict {
+		ips := strings.Split(fwdFor, ", ")
+		ip = ips[0]
+	} else if fwdFor := r.Header.Get("X-Forwarded-For"); fwdFor != "" && !strict {
 		ips := strings.Split(fwdFor, ", ")
 		ip = ips[0]
 	} else {