mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5925] [Question]: trustedXForwardedFor takes a trusted header name, not an IP - "127.0.0.1" never matches on XHTTP behind nginx #4109
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4109
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Necroflex1 on GitHub (Jul 13, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5925
Describe the bug
Summary
When an XHTTP (VLESS) inbound is placed behind a local nginx reverse proxy, the
sockopt.trustedXForwardedForoption does not take effect. Xray keeps logging theclient source address as
127.0.0.1(the nginx upstream) instead of the real clientIP that nginx passes via the
X-Forwarded-Forheader.As a result:
access.logshowsfrom 127.0.0.1for every connection.limitIp) does not work (all clients appear to come from127.0.0.1).
The panel writes the option into the generated config correctly, and Xray starts
without any parse error — but the value has no effect for the XHTTP transport.
Environment
client → nginx (HTTP/2 reverse proxy, listens on :443 with TLS) → Xray XHTTP inbound (listen 127.0.0.1:8443, security: none)What I already verified
log_formatproves nginx receives the real clientIP and forwards it:
myIP XFF="myIP"
myIPv6 XFF="myIPv6"
/usr/local/x-ui/bin/config.jsoncontains exactly:
Screenshots
No response
3x-ui version
3.5.0
Xray-core version
26.7.11
How did you install 3x-ui?
install.sh script
Operating system
24.04
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
Yes — Nginx
Before submitting
@github-actions[bot] commented on GitHub (Jul 13, 2026):
trustedXForwardedFordoes apply to XHTTP inbounds — confirmed both in the panel and in the Xray-core implementation — but the value must be an HTTP header name, not an IP address. Setting it to127.0.0.1will never match, which is why the source address never changes.How
trustedXForwardedForactually works (this is Xray-core semantics, not a panel choice)The option was added upstream in XTLS/Xray-core#5331 (https://github.com/XTLS/Xray-core/pull/5331), merged 2025-11-23 and included in
v26.7.11(go.modpinsgithub.com/xtls/xray-core v1.260327.1-0.20260711155151-...). For XHTTP (internallytransport/internet/splithttp/hub.goin xray-core; "splithttp" is the SplitHTTP/XHTTP transport), the matching logic is: for each entry configured intrustedXForwardedFor, Xray checks whether the incoming request carries an HTTP header whose name equals that entry, via the Go stdlib callrequest.Header.Values, regardless of the header value. If any entry matches as a header key, Xray parsesX-Forwarded-Forand rewrites the connection source address from it. If the list is empty, Xray falls back to always trustingX-Forwarded-Forunconditionally, the old pre-#5331 behavior.Each entry is checked purely as a header key, never compared against the connecting peer address. Setting it to
127.0.0.1makes Xray look for a request header literally named127.0.0.1— nginx never sends such a header, so the condition never matches and Xray keeps the raw TCP peer address, i.e. the nginx loopback source. That matches exactly thefrom 127.0.0.1shown inaccess.log.Fix, using the nginx config already posted: the
location /mypathblock already sendsproxy_set_header X-Real-IP $remote_addr;alongsideX-Forwarded-For.X-Real-IPis one of the four header names the panel UI already suggests for this exact field (inbound → Transport/Stream Settings → Sockopt → Trusted X-Forwarded-For, alongsideCF-Connecting-IP,True-Client-IP,X-Client-IP—frontend/src/pages/inbounds/form/transport/sockopt.tsx:216-219). Change the field from127.0.0.1toX-Real-IP, save, and restart Xray, so the generated config carries:No nginx changes are needed — it already sends that header.
The two reported problems are one problem. The panel does not parse
access.logorX-Forwarded-Foritself for online/IP-limit purposes; it reads the Xray-core connection tracking,statsUserOnline, via the online-stats gRPC API (internal/web/service/xray.go:826-861,internal/web/job/check_client_ip_job.go:30-33), which reports whatever address the Xray transport layer already recorded for the connection — the same addresstrustedXForwardedForrewrites as described above. Once the header name is corrected,access.log, the online list, and the IP limit should all reflect the real client IP together; no separate fix is needed for stats.For reference, XHTTP is listed in the panel
TRUSTED_HEADER_NETWORKSalongside WebSocket, HTTPUpgrade and gRPC (frontend/src/pages/inbounds/form/transport/sockopt.tsx:19), and this exact nginx plusX-Real-IPscenario is documented indocs/real-client-ip.md.Retitled and relabeled from
bugtoquestion—trustedXForwardedForis working as designed for XHTTP, the configured value just needs to be a header name rather than an IP. Closing, but reopen ifX-Real-IPdoes not resolve it and the updatedaccess.logoutput can be shared.This reply was generated automatically; a maintainer may follow up.