diff --git a/.env.example b/.env.example index 92a85eba..e52ce84f 100644 --- a/.env.example +++ b/.env.example @@ -9,4 +9,5 @@ XUI_VLESS_SNI="" #XUI_SUB_SUPPORT_URL="" #XUI_SUB_PROFILE_WEB_PAGE_URL="" #XUI_DEBUG="false" -#XUI_LOG_LEVEL="info" \ No newline at end of file +#XUI_LOG_LEVEL="info" +#XUI_GETREMOTEIP_PRIORITY_HEADER="" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 681d1fa2..886b14c7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,6 +51,7 @@ services: XUI_SUB_PROFILE_TITLE: "${XUI_SUB_PROFILE_TITLE:-}" XUI_SUB_SUPPORT_URL: "${XUI_SUB_SUPPORT_URL:-}" XUI_SUB_PROFILE_WEB_PAGE_URL: "${XUI_SUB_PROFILE_WEB_PAGE_URL:-}" + XUI_GETREMOTEIP_PRIORITY_HEADER: "${XUI_GETREMOTEIP_PRIORITY_HEADER:-}" XUI_DEBUG: "${XUI_DEBUG:-false}" XUI_LOG_LEVEL: "${XUI_LOG_LEVEL:-info}" tty: true diff --git a/web/controller/util.go b/web/controller/util.go index 04084f41..aa92e12a 100644 --- a/web/controller/util.go +++ b/web/controller/util.go @@ -3,6 +3,7 @@ package controller import ( "net" "net/http" + "os" "strings" "x-ui/config" @@ -13,7 +14,19 @@ import ( ) func getRemoteIp(c *gin.Context) string { - value := c.GetHeader("X-Real-IP") + var value string + priorityHeader := os.Getenv("XUI_GETREMOTEIP_PRIORITY_HEADER") + if priorityHeader != "" { + value = c.GetHeader(priorityHeader) + if strings.Contains(value, ",") { + ips := strings.Split(value, ",") + value = ips[0] + } + if value != "" { + return value + } + } + value = c.GetHeader("X-Real-IP") if value != "" { return value }