[GH-ISSUE #5925] [Question]: trustedXForwardedFor takes a trusted header name, not an IP - "127.0.0.1" never matches on XHTTP behind nginx #4109

Closed
opened 2026-10-31 20:37:14 +07:00 by bsakaguchi · 1 comment
Owner

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.trustedXForwardedFor option does not take effect. Xray keeps logging the
client source address as 127.0.0.1 (the nginx upstream) instead of the real client
IP that nginx passes via the X-Forwarded-For header.

As a result:

  • Xray access.log shows from 127.0.0.1 for every connection.
  • Per-user IP limit (limitIp) does not work (all clients appear to come from
    127.0.0.1).
  • Online clients / IP statistics in the panel are useless (everything is 127.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

  • Panel: 3x-ui 3.5.0
  • Xray core: v26.7.11
  • OS: Ubuntu 24.04
  • Topology: client → nginx (HTTP/2 reverse proxy, listens on :443 with TLS) → Xray XHTTP inbound (listen 127.0.0.1:8443, security: none)
  • No CDN in front of nginx (nginx sees the real client directly).

What I already verified

  1. nginx is correct. A debug log_format proves nginx receives the real client
    IP and forwards it:

myIP XFF="myIP"
myIPv6 XFF="myIPv6"

  1. The generated Xray config is correct. /usr/local/x-ui/bin/config.json
    contains exactly:
"sockopt": {
  "tcpcongestion": "bbr",
  "trustedXForwardedFor": ["127.0.0.1"]
}

    Xray starts without errors (no "unknown field" / parse error for
    trustedXForwardedFor).

    But the effect is missing. Xray access.log still shows:

2026/07/13 05:14:48 from 127.0.0.1:57174 accepted tcp:www.google.com:443 [in-8443-tcp >> direct] email: pocom5s

Expected from <real_client_ip>, got from 127.0.0.1.
nginx location (relevant part)

location /mypath {
    client_max_body_size 0;
    proxy_http_version 1.1;
    proxy_pass http://127.0.0.1:8443;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
    proxy_request_buffering off;
}

Additional note about IP limit / online stats

On startup the panel logs:

INFO - xray core supports the online-stats API; using connection-based onlines and access-log-free IP limit

Since online detection and the IP limit are computed from the connection address
(via the online-stats API) rather than from X-Forwarded-For / access.log, they always
resolve to 127.0.0.1 when the inbound sits behind a local nginx — even if
trustedXForwardedFor were applied to the log. So there seem to be two related
problems:

    trustedXForwardedFor is not applied to the XHTTP transport source address.
    Connection-based online-stats / IP limit ignore X-Forwarded-For entirely, so they
    break for any reverse-proxy setup on localhost.


### How to reproduce the problem

1. Create a VLESS + XHTTP inbound, `listen: 127.0.0.1`, `security: none`.
2. In inbound stream settings, set the "Real client IP" mode to the
   X-Forwarded-For option and value `127.0.0.1`
   (produces `sockopt.trustedXForwardedFor: ["127.0.0.1"]`).
3. Put nginx in front as an HTTP/2 reverse proxy that terminates TLS and sets
   `X-Forwarded-For` to the real client IP, `proxy_pass` to 127.0.0.1:8443.
4. Restart Xray.
5. Connect a client and watch `/var/log/x-ui/access.log`.

Result: `from 127.0.0.1` for every connection.
Expected: `from <real_client_ip>`.

### Expected behavior

With `trustedXForwardedFor` set to the nginx upstream (127.0.0.1), Xray should replace
the connection source address with the client IP taken from `X-Forwarded-For`, so that:
- access.log shows the real client IP,
- per-user IP limit (limitIp) works,
- online clients / IP statistics show real IPs.

### Actual behavior

_No response_

### Relevant logs

```shell

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

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
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.trustedXForwardedFor` option does not take effect. Xray keeps logging the client source address as `127.0.0.1` (the nginx upstream) instead of the real client IP that nginx passes via the `X-Forwarded-For` header. As a result: - Xray `access.log` shows `from 127.0.0.1` for every connection. - Per-user **IP limit** (`limitIp`) does not work (all clients appear to come from 127.0.0.1). - Online clients / IP statistics in the panel are useless (everything is 127.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 - Panel: 3x-ui 3.5.0 - Xray core: v26.7.11 - OS: Ubuntu 24.04 - Topology: `client → nginx (HTTP/2 reverse proxy, listens on :443 with TLS) → Xray XHTTP inbound (listen 127.0.0.1:8443, security: none)` - No CDN in front of nginx (nginx sees the real client directly). ## What I already verified 1. **nginx is correct.** A debug `log_format` proves nginx receives the real client IP and forwards it: myIP XFF="myIP" myIPv6 XFF="myIPv6" 2. **The generated Xray config is correct.** `/usr/local/x-ui/bin/config.json` contains exactly: ```json "sockopt": { "tcpcongestion": "bbr", "trustedXForwardedFor": ["127.0.0.1"] } Xray starts without errors (no "unknown field" / parse error for trustedXForwardedFor). But the effect is missing. Xray access.log still shows: 2026/07/13 05:14:48 from 127.0.0.1:57174 accepted tcp:www.google.com:443 [in-8443-tcp >> direct] email: pocom5s Expected from <real_client_ip>, got from 127.0.0.1. nginx location (relevant part) location /mypath { client_max_body_size 0; proxy_http_version 1.1; proxy_pass http://127.0.0.1:8443; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; proxy_request_buffering off; } Additional note about IP limit / online stats On startup the panel logs: INFO - xray core supports the online-stats API; using connection-based onlines and access-log-free IP limit Since online detection and the IP limit are computed from the connection address (via the online-stats API) rather than from X-Forwarded-For / access.log, they always resolve to 127.0.0.1 when the inbound sits behind a local nginx — even if trustedXForwardedFor were applied to the log. So there seem to be two related problems: trustedXForwardedFor is not applied to the XHTTP transport source address. Connection-based online-stats / IP limit ignore X-Forwarded-For entirely, so they break for any reverse-proxy setup on localhost. ### How to reproduce the problem 1. Create a VLESS + XHTTP inbound, `listen: 127.0.0.1`, `security: none`. 2. In inbound stream settings, set the "Real client IP" mode to the X-Forwarded-For option and value `127.0.0.1` (produces `sockopt.trustedXForwardedFor: ["127.0.0.1"]`). 3. Put nginx in front as an HTTP/2 reverse proxy that terminates TLS and sets `X-Forwarded-For` to the real client IP, `proxy_pass` to 127.0.0.1:8443. 4. Restart Xray. 5. Connect a client and watch `/var/log/x-ui/access.log`. Result: `from 127.0.0.1` for every connection. Expected: `from <real_client_ip>`. ### Expected behavior With `trustedXForwardedFor` set to the nginx upstream (127.0.0.1), Xray should replace the connection source address with the client IP taken from `X-Forwarded-For`, so that: - access.log shows the real client IP, - per-user IP limit (limitIp) works, - online clients / IP statistics show real IPs. ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:37:14 +07:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 13, 2026):

trustedXForwardedFor does 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 to 127.0.0.1 will never match, which is why the source address never changes.

How trustedXForwardedFor actually 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.mod pins github.com/xtls/xray-core v1.260327.1-0.20260711155151-...). For XHTTP (internally transport/internet/splithttp/hub.go in xray-core; "splithttp" is the SplitHTTP/XHTTP transport), the matching logic is: for each entry configured in trustedXForwardedFor, Xray checks whether the incoming request carries an HTTP header whose name equals that entry, via the Go stdlib call request.Header.Values, regardless of the header value. If any entry matches as a header key, Xray parses X-Forwarded-For and rewrites the connection source address from it. If the list is empty, Xray falls back to always trusting X-Forwarded-For unconditionally, 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.1 makes Xray look for a request header literally named 127.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 the from 127.0.0.1 shown in access.log.

Fix, using the nginx config already posted: the location /mypath block already sends proxy_set_header X-Real-IP $remote_addr; alongside X-Forwarded-For. X-Real-IP is one of the four header names the panel UI already suggests for this exact field (inbound → Transport/Stream Settings → Sockopt → Trusted X-Forwarded-For, alongside CF-Connecting-IP, True-Client-IP, X-Client-IP — frontend/src/pages/inbounds/form/transport/sockopt.tsx:216-219). Change the field from 127.0.0.1 to X-Real-IP, save, and restart Xray, so the generated config carries:

sockopt.trustedXForwardedFor: X-Real-IP

No nginx changes are needed — it already sends that header.

The two reported problems are one problem. The panel does not parse access.log or X-Forwarded-For itself 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 address trustedXForwardedFor rewrites 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_NETWORKS alongside WebSocket, HTTPUpgrade and gRPC (frontend/src/pages/inbounds/form/transport/sockopt.tsx:19), and this exact nginx plus X-Real-IP scenario is documented in docs/real-client-ip.md.

Retitled and relabeled from bug to question — trustedXForwardedFor is working as designed for XHTTP, the configured value just needs to be a header name rather than an IP. Closing, but reopen if X-Real-IP does not resolve it and the updated access.log output can be shared.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4954857475 --> @github-actions[bot] commented on GitHub (Jul 13, 2026): `trustedXForwardedFor` does 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 to `127.0.0.1` will never match, which is why the source address never changes. **How `trustedXForwardedFor` actually 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.mod` pins `github.com/xtls/xray-core v1.260327.1-0.20260711155151-...`). For XHTTP (internally `transport/internet/splithttp/hub.go` in xray-core; "splithttp" is the SplitHTTP/XHTTP transport), the matching logic is: for each entry configured in `trustedXForwardedFor`, Xray checks whether the incoming request carries an HTTP header whose name equals that entry, via the Go stdlib call `request.Header.Values`, regardless of the header value. If any entry matches as a header key, Xray parses `X-Forwarded-For` and rewrites the connection source address from it. If the list is empty, Xray falls back to always trusting `X-Forwarded-For` unconditionally, 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.1` makes Xray look for a request header literally named `127.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 the `from 127.0.0.1` shown in `access.log`. **Fix, using the nginx config already posted:** the `location /mypath` block already sends `proxy_set_header X-Real-IP $remote_addr;` alongside `X-Forwarded-For`. `X-Real-IP` is one of the four header names the panel UI already suggests for this exact field (inbound → Transport/Stream Settings → Sockopt → Trusted X-Forwarded-For, alongside `CF-Connecting-IP`, `True-Client-IP`, `X-Client-IP` — `frontend/src/pages/inbounds/form/transport/sockopt.tsx:216-219`). Change the field from `127.0.0.1` to `X-Real-IP`, save, and restart Xray, so the generated config carries: ``` sockopt.trustedXForwardedFor: X-Real-IP ``` No nginx changes are needed — it already sends that header. **The two reported problems are one problem.** The panel does not parse `access.log` or `X-Forwarded-For` itself 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 address `trustedXForwardedFor` rewrites 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_NETWORKS` alongside WebSocket, HTTPUpgrade and gRPC (`frontend/src/pages/inbounds/form/transport/sockopt.tsx:19`), and this exact nginx plus `X-Real-IP` scenario is documented in `docs/real-client-ip.md`. Retitled and relabeled from `bug` to `question` — `trustedXForwardedFor` is working as designed for XHTTP, the configured value just needs to be a header name rather than an IP. Closing, but reopen if `X-Real-IP` does not resolve it and the updated `access.log` output can be shared. *This reply was generated automatically; a maintainer may follow up.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4109
No description provided.