Browse Source

use cloudflare ip

Tobias von Dewitz 5 năm trước cách đây
mục cha
commit
f7fc968d86
1 tập tin đã thay đổi với 4 bổ sung1 xóa
  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 {