XTLS / Xray-core

Xray, Penetrates Everything. Also the best v2ray-core, with XTLS support. Fully compatible configuration.
https://t.me/projectXray
Mozilla Public License 2.0
25.63k stars 3.96k forks source link

API Interface not working #3025

Closed zoheirkabuli closed 9 months ago

zoheirkabuli commented 9 months ago

Hello I hope you are well I run xray by docker and enabled api interface in config but it is not working with grpcurl I would be thankful if guide me I'll put my config and grpcurl down below

My config:

{
  "api": {
    "services": [
      "HandlerService",
      "LoggerService",
      "StatsService",
      "ReflectionService"
    ],
    "tag": "api"
  },
  "dns": null,
  "fakeDns": null,
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 62789,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "sniffing": null,
      "streamSettings": null,
      "tag": "api"
    }
  ],
  "log": {
    "access": "none",
    "dnsLog": false,
    "loglevel": "warning"
  },
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {},
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "settings": {},
      "tag": "blocked"
    }
  ],
  "policy": {
    "levels": {
      "0": {
        "statsUserDownlink": true,
        "statsUserUplink": true
      }
    },
    "system": {
      "statsInboundDownlink": true,
      "statsInboundUplink": true,
      "statsOutboundDownlink": true,
      "statsOutboundUplink": true
    }
  },
  "reverse": null,
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "inboundTag": ["api"],
        "outboundTag": "api",
        "type": "field"
      }
    ]
  },
  "stats": {},
  "transport": null
}

grpcurl output:

$ grpcurl -plaintext localhost:62789 list
Failed to dial target host "localhost:62789": context deadline exceeded
us254 commented 9 months ago

the API is listening on 127.0.0.1 within the Docker container's network namespace. This means it's not accessible from outside the container, including your host machine.

To make the API accessible, you'll need to adjust the listen address to 0.0.0.0 in the inbound configuration for the API, which will allow connections from any IP address, not just 127.0.0.1. modify the inbounds section of your configuration:

"inbounds": [
  {
    "listen": "0.0.0.0",
    "port": 62789,
    "protocol": "dokodemo-door",
    "settings": {
      "address": "127.0.0.1"
    },
    "tag": "api"
  }
]

when you run the Docker container, you need to ensure that the port 62789 is published to the host machine. do this by using the -p flag in your docker run command:

docker run -d --name xray-container -p 62789:62789 xray-image-name

try running grpcurl again:

grpcurl -plaintext localhost:62789 list

double-check that there are no firewall rules on your host machine that may be blocking the connection to the specified port.

zoheirkabuli commented 9 months ago

@us254 Thanks man It Works