[GH-ISSUE #5126] [Feature]: Expose MTG reverse-proxy / HAProxy options for MTProto inbounds #3604

Closed
opened 2026-10-31 20:33:39 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @deepru on GitHub (Jun 9, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5126

Yes. 3x-ui v3.3.0 added MTProto FakeTLS support through a managed mtg sidecar, and the basic lifecycle works well. However, the current MTG integration is difficult to use safely behind HAProxy / reverse proxy / ELB setups where the public port is 443 and the MTG inbound itself listens only on loopback.

The current generated MTG config is minimal. In my runtime test, 3x-ui created this config for a loopback MTProto inbound:

secret = "ee<redacted>"
bind-to = "127.0.0.1:8689"

[stats.prometheus]
enabled = true
bind-to = "127.0.0.1:1535"
http-path = "/metrics"
metric-prefix = "mtg"

This works for the sidecar itself, but it does not expose some existing MTG options that are needed for reverse-proxy deployments.

The main problem is domain-fronting fallback behavior. When MTG receives a non-Telegram / stale / HTTPS-like request, it routes the request to the FakeTLS domain from the secret. In a reverse-proxy setup, that domain often points back to the same public :443 listener.

For example:

client HTTPS-like request
-> HAProxy :443
-> MTG on 127.0.0.1:<internal_port>
-> MTG domain-fronting fallback to fakeTlsDomain:443
-> same public HAProxy :443 again
-> possible routing loop if HAProxy routes that SNI back to MTG

I tested this directly with a 3x-ui-created MTProto inbound using:

listen=127.0.0.1
port=8689
protocol=mtproto
fakeTlsDomain=tg2.example.com

Then I sent a direct HTTPS-like request to MTG with SNI set to the FakeTLS domain:

curl -vkI \
  --resolve tg2.example.com:8689:127.0.0.1 \
  https://tg2.example.com:8689/health

The request returned an nginx 200 OK, and the MTG metric mtg_domain_fronting increased from 0 to 1. This confirms that MTG fronted the request to the public FakeTLS domain. This is expected MTG behavior, but without a configurable local domain-fronting target it is unsafe for a clean HAProxy/ELB mode.

There is also a share-link problem. mtg access generated a link using the public IP and the internal MTG port:

server=<public-ip>
port=8689

For a reverse-proxy setup, the correct user-facing link should be:

server=tg2.example.com
port=443

So 3x-ui needs a way to override the public host and public port used for MTProto share links.

Finally, MTG supports PROXY protocol, which is useful when HAProxy / ELB passes the real client IP to the backend. 3x-ui currently does not expose a proxy-protocol-listener option for MTProto inbounds.

Describe the solution you'd like

Please add a reverse-proxy / HAProxy / ELB mode for MTProto inbounds, or expose the needed MTG options in the MTProto inbound settings.

The requested options are:

1. Domain-fronting target override

Add fields to the MTProto inbound configuration, for example:

{
  "domainFronting": {
    "enabled": true,
    "host": "127.0.0.1",
    "port": 9443,
    "proxyProtocol": false
  }
}

Expected generated MTG config shape could be similar to:

secret = "ee<redacted>"
bind-to = "127.0.0.1:8689"

[domain-fronting]
enabled = true
host = "127.0.0.1"
port = 9443

The exact key names can be different if you prefer another schema. The important part is that rejected / stale / HTTPS-like traffic can be forwarded to a local fallback backend instead of always going to fakeTlsDomain:443.

Add MTProto inbound fields such as:

{
  "externalProxy": {
    "host": "tg2.example.com",
    "port": 443
  }
}

or reuse the existing external proxy/share-link model if possible.

Expected behavior:

MTG listens on:       127.0.0.1:8689
Public endpoint is:   tg2.example.com:443
Generated tg:// link: server=tg2.example.com&port=443

This is needed because in a reverse-proxy setup the internal MTG bind port is not publicly reachable and should not be shown to users.

3. PROXY protocol listener option

Expose MTG's PROXY protocol listener option for MTProto inbounds, for example:

{
  "proxyProtocolListener": true
}

This is useful when HAProxy / ELB forwards real client IP information to MTG.

4. Suggested UI placement

On the MTProto inbound edit/create page, add an optional advanced section, for example:

MTProto advanced / Reverse proxy mode

[ ] Enable reverse-proxy / HAProxy mode

Public share link:
- Public host
- Public port

Domain-fronting fallback:
- Fallback host
- Fallback port
- Use PROXY protocol to fallback backend, if supported/needed

Listener:
- Accept PROXY protocol from HAProxy/ELB

Defaults should preserve the current behavior for simple non-reverse-proxy deployments.

5. API behavior

The same options should be available through /panel/api/inbounds/add and /panel/api/inbounds/update, so external automation can create MTProto inbounds safely.

6. Expected edge-case behavior

  • If no public host/port override is configured, keep the current link generation behavior.
  • If no domain-fronting override is configured, keep the current MTG default behavior.
  • If listen=127.0.0.1, generated public links should not automatically use 127.0.0.1 or the internal port when a public override is configured.
  • Existing MTProto inbounds should continue to work after upgrade.
  • The options should not affect non-MTProto inbounds.

Alternatives you've considered

1. Keep MTG exposed directly on a public port.

This works for simple deployments, but it does not fit setups where all public TLS traffic is multiplexed on 443 through HAProxy or another reverse proxy.

2. Manually patch /usr/local/x-ui/bin/mtproto/mtg-<id>.toml.

This is fragile because 3x-ui owns and regenerates the MTG config. It also breaks the panel as the source of truth.

3. Use another standalone MTProto implementation outside 3x-ui.

This works, but it defeats the purpose of adding managed MTProto support to 3x-ui. The new v3.3.0 MTG sidecar lifecycle works well, so it would be better to expose the missing MTG options in 3x-ui instead of maintaining a parallel service.

4. Use outbound proxy support for MTG.

Outbound proxy support is useful for another scenario, but it does not solve this reverse-proxy problem. This request is about inbound HAProxy / ELB mode, domain-fronting fallback target override, generated public share links, and optionally PROXY protocol from the load balancer to MTG.

Concrete use case

A server runs several services behind one public TLS port:

public :443
-> HAProxy SNI router
   -> VLESS / Xray backend
   -> 3x-ui panel backend
   -> MTProto / MTG backend
   -> local nginx fallback backend

The desired MTProto deployment is:

User connects to:        tg2.example.com:443
HAProxy routes SNI to:   127.0.0.1:8689
MTG listens on:          127.0.0.1:8689
Fallback target:         127.0.0.1:<local-nginx-fallback-port>
Generated user link:     tg://proxy?server=tg2.example.com&port=443&secret=...

This allows MTProto FakeTLS to run cleanly behind HAProxy without opening an additional public port and without exposing the internal MTG port to users.

I tested this on a clean Ubuntu 24.04 VPS with 3x-ui v3.3.0:

  • Created a MTProto inbound through the 3x-ui API.
  • listen=127.0.0.1
  • port=8689
  • protocol=mtproto
  • fakeTlsDomain=tg2.example.com

Observed result:

DB inbound:
id=2
remark=xpam-mtg-probe
listen=127.0.0.1
port=8689
protocol=mtproto
tag=in-8689-tcp

Generated config:
/usr/local/x-ui/bin/mtproto/mtg-2.toml

Process:
mtg-linux-amd64 run bin/mtproto/mtg-2.toml

Listeners:
127.0.0.1:8689  MTG
127.0.0.1:1535  Prometheus metrics

Generated MTG config:

secret = "ee<redacted>"
bind-to = "127.0.0.1:8689"

[stats.prometheus]
enabled = true
bind-to = "127.0.0.1:1535"
http-path = "/metrics"
metric-prefix = "mtg"

The MTG lifecycle worked correctly:

create:  OK
run:     OK
metrics: OK
delete:  OK
cleanup: OK

Deleting the inbound through the API removed the DB row, stopped the MTG sidecar, removed the generated MTG config, and removed the loopback listeners.

The missing part is not MTG lifecycle stability. The missing part is exposing the MTG options needed for reverse-proxy / HAProxy / ELB mode.

Mockups, screenshots, or examples

Example desired generated MTG config:

secret = "ee<redacted>"
bind-to = "127.0.0.1:8689"
proxy-protocol-listener = true

[domain-fronting]
enabled = true
host = "127.0.0.1"
port = 9443

[stats.prometheus]
enabled = true
bind-to = "127.0.0.1:1535"
http-path = "/metrics"
metric-prefix = "mtg"

Example desired share-link behavior:

Internal bind:
127.0.0.1:8689

Public endpoint:
tg2.example.com:443

Generated link:
tg://proxy?server=tg2.example.com&port=443&secret=<redacted>

Example UI section:

MTProto advanced / Reverse proxy mode

[ ] Enable reverse-proxy / HAProxy mode

Public share link
  Public host: tg2.example.com
  Public port: 443

Domain-fronting fallback
  Fallback host: 127.0.0.1
  Fallback port: 9443

Listener
  [ ] Accept PROXY protocol from HAProxy/ELB

Related but not duplicate:

  • #5076 added the base MTProto / MTG sidecar support.
  • #5107 fixed MTG orphan/log/export-link issues.
  • #5115 requests outbound proxy support for MTG; this request is about inbound reverse-proxy / HAProxy mode.
  • Older generic MTProto feature requests are already covered by v3.3.0; this request is specifically about advanced MTG options for reverse-proxy deployments.

Which parts of the panel would this affect?

Backend (API endpoints, login, settings)

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @deepru on GitHub (Jun 9, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5126 ### Is your feature request related to a problem? Yes. 3x-ui v3.3.0 added MTProto FakeTLS support through a managed `mtg` sidecar, and the basic lifecycle works well. However, the current MTG integration is difficult to use safely behind HAProxy / reverse proxy / ELB setups where the public port is `443` and the MTG inbound itself listens only on loopback. The current generated MTG config is minimal. In my runtime test, 3x-ui created this config for a loopback MTProto inbound: ```toml secret = "ee<redacted>" bind-to = "127.0.0.1:8689" [stats.prometheus] enabled = true bind-to = "127.0.0.1:1535" http-path = "/metrics" metric-prefix = "mtg" ``` This works for the sidecar itself, but it does not expose some existing MTG options that are needed for reverse-proxy deployments. The main problem is domain-fronting fallback behavior. When MTG receives a non-Telegram / stale / HTTPS-like request, it routes the request to the FakeTLS domain from the secret. In a reverse-proxy setup, that domain often points back to the same public `:443` listener. For example: ```text client HTTPS-like request -> HAProxy :443 -> MTG on 127.0.0.1:<internal_port> -> MTG domain-fronting fallback to fakeTlsDomain:443 -> same public HAProxy :443 again -> possible routing loop if HAProxy routes that SNI back to MTG ``` I tested this directly with a 3x-ui-created MTProto inbound using: ```text listen=127.0.0.1 port=8689 protocol=mtproto fakeTlsDomain=tg2.example.com ``` Then I sent a direct HTTPS-like request to MTG with SNI set to the FakeTLS domain: ```bash curl -vkI \ --resolve tg2.example.com:8689:127.0.0.1 \ https://tg2.example.com:8689/health ``` The request returned an nginx `200 OK`, and the MTG metric `mtg_domain_fronting` increased from `0` to `1`. This confirms that MTG fronted the request to the public FakeTLS domain. This is expected MTG behavior, but without a configurable local domain-fronting target it is unsafe for a clean HAProxy/ELB mode. There is also a share-link problem. `mtg access` generated a link using the public IP and the internal MTG port: ```text server=<public-ip> port=8689 ``` For a reverse-proxy setup, the correct user-facing link should be: ```text server=tg2.example.com port=443 ``` So 3x-ui needs a way to override the public host and public port used for MTProto share links. Finally, MTG supports PROXY protocol, which is useful when HAProxy / ELB passes the real client IP to the backend. 3x-ui currently does not expose a `proxy-protocol-listener` option for MTProto inbounds. ### Describe the solution you'd like Please add a reverse-proxy / HAProxy / ELB mode for MTProto inbounds, or expose the needed MTG options in the MTProto inbound settings. The requested options are: ### 1. Domain-fronting target override Add fields to the MTProto inbound configuration, for example: ```json { "domainFronting": { "enabled": true, "host": "127.0.0.1", "port": 9443, "proxyProtocol": false } } ``` Expected generated MTG config shape could be similar to: ```toml secret = "ee<redacted>" bind-to = "127.0.0.1:8689" [domain-fronting] enabled = true host = "127.0.0.1" port = 9443 ``` The exact key names can be different if you prefer another schema. The important part is that rejected / stale / HTTPS-like traffic can be forwarded to a local fallback backend instead of always going to `fakeTlsDomain:443`. ### 2. Public share-link host/port override Add MTProto inbound fields such as: ```json { "externalProxy": { "host": "tg2.example.com", "port": 443 } } ``` or reuse the existing external proxy/share-link model if possible. Expected behavior: ```text MTG listens on: 127.0.0.1:8689 Public endpoint is: tg2.example.com:443 Generated tg:// link: server=tg2.example.com&port=443 ``` This is needed because in a reverse-proxy setup the internal MTG bind port is not publicly reachable and should not be shown to users. ### 3. PROXY protocol listener option Expose MTG's PROXY protocol listener option for MTProto inbounds, for example: ```json { "proxyProtocolListener": true } ``` This is useful when HAProxy / ELB forwards real client IP information to MTG. ### 4. Suggested UI placement On the MTProto inbound edit/create page, add an optional advanced section, for example: ```text MTProto advanced / Reverse proxy mode [ ] Enable reverse-proxy / HAProxy mode Public share link: - Public host - Public port Domain-fronting fallback: - Fallback host - Fallback port - Use PROXY protocol to fallback backend, if supported/needed Listener: - Accept PROXY protocol from HAProxy/ELB ``` Defaults should preserve the current behavior for simple non-reverse-proxy deployments. ### 5. API behavior The same options should be available through `/panel/api/inbounds/add` and `/panel/api/inbounds/update`, so external automation can create MTProto inbounds safely. ### 6. Expected edge-case behavior - If no public host/port override is configured, keep the current link generation behavior. - If no domain-fronting override is configured, keep the current MTG default behavior. - If `listen=127.0.0.1`, generated public links should not automatically use `127.0.0.1` or the internal port when a public override is configured. - Existing MTProto inbounds should continue to work after upgrade. - The options should not affect non-MTProto inbounds. ### Alternatives you've considered ### 1. Keep MTG exposed directly on a public port. This works for simple deployments, but it does not fit setups where all public TLS traffic is multiplexed on `443` through HAProxy or another reverse proxy. ### 2. Manually patch `/usr/local/x-ui/bin/mtproto/mtg-<id>.toml`. This is fragile because 3x-ui owns and regenerates the MTG config. It also breaks the panel as the source of truth. ### 3. Use another standalone MTProto implementation outside 3x-ui. This works, but it defeats the purpose of adding managed MTProto support to 3x-ui. The new v3.3.0 MTG sidecar lifecycle works well, so it would be better to expose the missing MTG options in 3x-ui instead of maintaining a parallel service. ### 4. Use outbound proxy support for MTG. Outbound proxy support is useful for another scenario, but it does not solve this reverse-proxy problem. This request is about inbound HAProxy / ELB mode, domain-fronting fallback target override, generated public share links, and optionally PROXY protocol from the load balancer to MTG. ### Concrete use case A server runs several services behind one public TLS port: ```text public :443 -> HAProxy SNI router -> VLESS / Xray backend -> 3x-ui panel backend -> MTProto / MTG backend -> local nginx fallback backend ``` The desired MTProto deployment is: ```text User connects to: tg2.example.com:443 HAProxy routes SNI to: 127.0.0.1:8689 MTG listens on: 127.0.0.1:8689 Fallback target: 127.0.0.1:<local-nginx-fallback-port> Generated user link: tg://proxy?server=tg2.example.com&port=443&secret=... ``` This allows MTProto FakeTLS to run cleanly behind HAProxy without opening an additional public port and without exposing the internal MTG port to users. I tested this on a clean Ubuntu 24.04 VPS with 3x-ui v3.3.0: - Created a MTProto inbound through the 3x-ui API. - `listen=127.0.0.1` - `port=8689` - `protocol=mtproto` - `fakeTlsDomain=tg2.example.com` Observed result: ```text DB inbound: id=2 remark=xpam-mtg-probe listen=127.0.0.1 port=8689 protocol=mtproto tag=in-8689-tcp Generated config: /usr/local/x-ui/bin/mtproto/mtg-2.toml Process: mtg-linux-amd64 run bin/mtproto/mtg-2.toml Listeners: 127.0.0.1:8689 MTG 127.0.0.1:1535 Prometheus metrics ``` Generated MTG config: ```toml secret = "ee<redacted>" bind-to = "127.0.0.1:8689" [stats.prometheus] enabled = true bind-to = "127.0.0.1:1535" http-path = "/metrics" metric-prefix = "mtg" ``` The MTG lifecycle worked correctly: ```text create: OK run: OK metrics: OK delete: OK cleanup: OK ``` Deleting the inbound through the API removed the DB row, stopped the MTG sidecar, removed the generated MTG config, and removed the loopback listeners. The missing part is not MTG lifecycle stability. The missing part is exposing the MTG options needed for reverse-proxy / HAProxy / ELB mode. ### Mockups, screenshots, or examples Example desired generated MTG config: ```toml secret = "ee<redacted>" bind-to = "127.0.0.1:8689" proxy-protocol-listener = true [domain-fronting] enabled = true host = "127.0.0.1" port = 9443 [stats.prometheus] enabled = true bind-to = "127.0.0.1:1535" http-path = "/metrics" metric-prefix = "mtg" ``` Example desired share-link behavior: ```text Internal bind: 127.0.0.1:8689 Public endpoint: tg2.example.com:443 Generated link: tg://proxy?server=tg2.example.com&port=443&secret=<redacted> ``` Example UI section: ```text MTProto advanced / Reverse proxy mode [ ] Enable reverse-proxy / HAProxy mode Public share link Public host: tg2.example.com Public port: 443 Domain-fronting fallback Fallback host: 127.0.0.1 Fallback port: 9443 Listener [ ] Accept PROXY protocol from HAProxy/ELB ``` Related but not duplicate: - #5076 added the base MTProto / MTG sidecar support. - #5107 fixed MTG orphan/log/export-link issues. - #5115 requests outbound proxy support for MTG; this request is about inbound reverse-proxy / HAProxy mode. - Older generic MTProto feature requests are already covered by v3.3.0; this request is specifically about advanced MTG options for reverse-proxy deployments. ### Which parts of the panel would this affect? Backend (API endpoints, login, settings) ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 9, 2026):

Thanks for the detailed report — the use case is clear and the code analysis below confirms none of the three requested options exist yet.

What the code currently does

MTG config generation (mtproto/manager.go, writeConfig, line 285–292):

The generated TOML is always exactly:

secret = "ee..."
bind-to = "host:port"

[stats.prometheus]
enabled = true
bind-to = "127.0.0.1:<auto-port>"
http-path = "/metrics"
metric-prefix = "mtg"

No [domain-fronting] section and no proxy-protocol-listener key are ever written. The Instance struct (lines 20–26) only carries Id, Tag, Listen, Port, and Secret — no field for any of the three requested options.

Share-link generation (sub/subService.go, genMtprotoLink, lines 383–406):

params := map[string]string{
    "server": s.resolveInboundAddress(inbound),
    "port":   fmt.Sprintf("%d", inbound.Port),
    "secret": secret,
}

resolveInboundAddress skips loopback/wildcard addresses and falls back to the subscriber's request hostname — so a listen=127.0.0.1 inbound will use the subscriber host, not 127.0.0.1. But there is no override mechanism: you cannot force server=tg2.example.com and port=443 from the inbound config today.

MTProto settings schema (frontend/src/schemas/protocols/inbound/mtproto.ts):

export const MtprotoInboundSettingsSchema = z.object({
  fakeTlsDomain: z.string().default('www.cloudflare.com'),
  secret: z.string().default(''),
});

Only fakeTlsDomain and secret are stored. The externalProxy / streamSettings mechanism that other protocols use does not apply to MTProto — it is not an Xray protocol and has no streamSettings.


What would need to change for each requested option

1. Domain-fronting fallback target override

  • Add fields (e.g. domainFronting: { enabled, host, port }) to MtprotoInboundSettings in the frontend schema and in InstanceFromInbound / Instance in mtproto/manager.go.
  • Pass them through to writeConfig and emit the [domain-fronting] TOML block conditionally.
  • Add matching form fields in frontend/src/pages/inbounds/form/protocols/mtproto.tsx.
  • Add fields (e.g. publicHost, publicPort) to MtprotoInboundSettings.
  • Update genMtprotoLink in sub/subService.go to use those fields when set, falling back to the current resolveInboundAddress/inbound.Port logic.
  • Front-end form fields in mtproto.tsx.

3. PROXY protocol listener

  • Add a boolean field (e.g. proxyProtocolListener) to MtprotoInboundSettings and Instance.
  • Emit proxy-protocol-listener = true in writeConfig when set.
  • Include it in the fingerprint string in Instance.fingerprint() so a config change triggers a restart.

Notes

  • All three changes are backwards-compatible: existing inbounds that don't set the new fields keep the current behavior.
  • The Instance.fingerprint() method (line 36–38) drives restart detection. Any new config option that should trigger a sidecar restart must be included in that fingerprint.
  • MTProto has no streamSettings — the existing externalProxy mechanism (used for VLESS/VMess) cannot be reused here. A dedicated fields approach in settings JSON is the right path.
  • The API automatically reflects whatever is stored in the settings JSON column, so API support (point 5 in the request) would come for free once the backend and model are updated.

This is a well-scoped feature request with no duplicate. PRs are welcome.

<!-- gh-comment-id:4658598970 --> @github-actions[bot] commented on GitHub (Jun 9, 2026): Thanks for the detailed report — the use case is clear and the code analysis below confirms none of the three requested options exist yet. ## What the code currently does **MTG config generation** (`mtproto/manager.go`, `writeConfig`, line 285–292): The generated TOML is always exactly: ```toml secret = "ee..." bind-to = "host:port" [stats.prometheus] enabled = true bind-to = "127.0.0.1:<auto-port>" http-path = "/metrics" metric-prefix = "mtg" ``` No `[domain-fronting]` section and no `proxy-protocol-listener` key are ever written. The `Instance` struct (lines 20–26) only carries `Id`, `Tag`, `Listen`, `Port`, and `Secret` — no field for any of the three requested options. **Share-link generation** (`sub/subService.go`, `genMtprotoLink`, lines 383–406): ```go params := map[string]string{ "server": s.resolveInboundAddress(inbound), "port": fmt.Sprintf("%d", inbound.Port), "secret": secret, } ``` `resolveInboundAddress` skips loopback/wildcard addresses and falls back to the subscriber's request hostname — so a `listen=127.0.0.1` inbound will use the subscriber host, not `127.0.0.1`. But there is no override mechanism: you cannot force `server=tg2.example.com` and `port=443` from the inbound config today. **MTProto settings schema** (`frontend/src/schemas/protocols/inbound/mtproto.ts`): ```ts export const MtprotoInboundSettingsSchema = z.object({ fakeTlsDomain: z.string().default('www.cloudflare.com'), secret: z.string().default(''), }); ``` Only `fakeTlsDomain` and `secret` are stored. The `externalProxy` / `streamSettings` mechanism that other protocols use does not apply to MTProto — it is not an Xray protocol and has no `streamSettings`. --- ## What would need to change for each requested option ### 1. Domain-fronting fallback target override - Add fields (e.g. `domainFronting: { enabled, host, port }`) to `MtprotoInboundSettings` in the frontend schema and in `InstanceFromInbound` / `Instance` in `mtproto/manager.go`. - Pass them through to `writeConfig` and emit the `[domain-fronting]` TOML block conditionally. - Add matching form fields in `frontend/src/pages/inbounds/form/protocols/mtproto.tsx`. ### 2. Public share-link host/port override - Add fields (e.g. `publicHost`, `publicPort`) to `MtprotoInboundSettings`. - Update `genMtprotoLink` in `sub/subService.go` to use those fields when set, falling back to the current `resolveInboundAddress`/`inbound.Port` logic. - Front-end form fields in `mtproto.tsx`. ### 3. PROXY protocol listener - Add a boolean field (e.g. `proxyProtocolListener`) to `MtprotoInboundSettings` and `Instance`. - Emit `proxy-protocol-listener = true` in `writeConfig` when set. - Include it in the fingerprint string in `Instance.fingerprint()` so a config change triggers a restart. --- ## Notes - All three changes are backwards-compatible: existing inbounds that don't set the new fields keep the current behavior. - The `Instance.fingerprint()` method (line 36–38) drives restart detection. Any new config option that should trigger a sidecar restart must be included in that fingerprint. - MTProto has no `streamSettings` — the existing `externalProxy` mechanism (used for VLESS/VMess) cannot be reused here. A dedicated fields approach in `settings` JSON is the right path. - The API automatically reflects whatever is stored in the `settings` JSON column, so API support (point 5 in the request) would come for free once the backend and model are updated. This is a well-scoped feature request with no duplicate. PRs are welcome.
Author
Owner

@deepru commented on GitHub (Jun 9, 2026):

Thanks for checking the code paths and confirming the scope.

Your summary matches exactly what I observed in runtime tests. I agree that a dedicated fields approach in the MTProto settings JSON is the cleanest path, since MTProto is managed by mtg and does not use Xray streamSettings.

The proposed implementation plan also looks right to me:

  • add the new MTProto settings fields in the frontend schema and form;
  • pass them into InstanceFromInbound / Instance;
  • emit the optional MTG TOML keys in writeConfig;
  • include config-affecting fields in Instance.fingerprint();
  • use publicHost / publicPort in genMtprotoLink when set;
  • keep current behavior as default for existing/simple deployments.

I can help test a PR in a real HAProxy / loopback MTG setup once available. I may also try to prepare a small PR if I have enough time.

<!-- gh-comment-id:4658660272 --> @deepru commented on GitHub (Jun 9, 2026): Thanks for checking the code paths and confirming the scope. Your summary matches exactly what I observed in runtime tests. I agree that a dedicated fields approach in the MTProto settings JSON is the cleanest path, since MTProto is managed by `mtg` and does not use Xray `streamSettings`. The proposed implementation plan also looks right to me: * add the new MTProto settings fields in the frontend schema and form; * pass them into `InstanceFromInbound` / `Instance`; * emit the optional MTG TOML keys in `writeConfig`; * include config-affecting fields in `Instance.fingerprint()`; * use `publicHost` / `publicPort` in `genMtprotoLink` when set; * keep current behavior as default for existing/simple deployments. I can help test a PR in a real HAProxy / loopback MTG setup once available. I may also try to prepare a small PR if I have enough time.
Author
Owner

@MHSanaei commented on GitHub (Jul 3, 2026):

Status update — two of the three requested knobs landed shortly after this was filed (commit 6c159469): MTProto inbounds now expose domain-fronting overrides (ip/port/proxy-protocol) and a PROXY-protocol listener toggle in the inbound form, so the HAProxy/loopback deployment works.

The remaining gap is (2): the generated tg://proxy link still uses the inbound's own address/port rather than a configurable public host/port. Keeping this open for that part — the likely shape is optional publicHost/publicPort fields in the MTProto settings preferred by both link generators.

<!-- gh-comment-id:4873986628 --> @MHSanaei commented on GitHub (Jul 3, 2026): Status update — two of the three requested knobs landed shortly after this was filed (commit 6c159469): MTProto inbounds now expose **domain-fronting overrides** (ip/port/proxy-protocol) and a **PROXY-protocol listener** toggle in the inbound form, so the HAProxy/loopback deployment works. The remaining gap is (2): the generated `tg://proxy` link still uses the inbound's own address/port rather than a configurable public host/port. Keeping this open for that part — the likely shape is optional `publicHost`/`publicPort` fields in the MTProto settings preferred by both link generators.
Author
Owner

@deepru commented on GitHub (Jul 12, 2026):

Still reproduces on v3.5.0 (now with the multi-client MTProto model), specifically the share-link port exposure part. Adding the exact code location and a concrete fix.

Root cause — genMtprotoLink (internal/sub/service.go) takes the address from shareAddr but hardcodes the port to the inbound's listen port:

"server": s.resolveInboundAddress(inbound), // shareAddr honored → correct host
"port":   fmt.Sprintf("%d", inbound.Port),  // always the internal listen port
"secret": resolved.Secret,

Why VLESS/VMess don't have this: their links honor streamSettings.externalProxy[].port; MTProto has no streamSettings/externalProxy, so no equivalent lever.

Minimal fix: let MTProto carry a public share port (a sharePort field, or shareAddr as host:port) and use it in genMtprotoLink instead of inbound.Port. (The domain-fronting-loop and PROXY-protocol items in this issue are separate.)

Scope note: pure link generation in 3x-ui; the mtg/mtg-multi backend is not involved.

<!-- gh-comment-id:4953135125 --> @deepru commented on GitHub (Jul 12, 2026): Still reproduces on **v3.5.0** (now with the multi-client MTProto model), specifically the **share-link port exposure** part. Adding the exact code location and a concrete fix. **Root cause** — `genMtprotoLink` (`internal/sub/service.go`) takes the address from `shareAddr` but hardcodes the port to the inbound's listen port: ```go "server": s.resolveInboundAddress(inbound), // shareAddr honored → correct host "port": fmt.Sprintf("%d", inbound.Port), // always the internal listen port "secret": resolved.Secret, ``` Why VLESS/VMess don't have this: their links honor `streamSettings.externalProxy[].port`; MTProto has no `streamSettings`/`externalProxy`, so no equivalent lever. **Minimal fix:** let MTProto carry a public share port (a `sharePort` field, or `shareAddr` as `host:port`) and use it in `genMtprotoLink` instead of `inbound.Port`. (The domain-fronting-loop and PROXY-protocol items in this issue are separate.) Scope note: pure link generation in 3x-ui; the mtg/mtg-multi backend is not involved.
Author
Owner

@SiegfriedSchmidt commented on GitHub (Aug 2, 2026):

problem still persists in v3.6.0

<!-- gh-comment-id:5156998088 --> @SiegfriedSchmidt commented on GitHub (Aug 2, 2026): problem still persists in v3.6.0
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#3604
No description provided.