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
23.17k stars 3.71k forks source link

API Fails to Dial dokodemo-door port #1559

Closed PouriaMzn closed 3 months ago

PouriaMzn commented 1 year ago

Hello everyone, I'm using Xray 1.7.2 and I have a problem using the API, here is my config:

{
  "log": {
    "loglevel": "info",
     "access": "/home/ubuntu/xray_log/access.log",
     "error": "/home/ubuntu/xray_log/error.log"
  },
  "stats": {},
  "api": {
    "tag": "api",
    "services": ["HandlerService", "LoggerService", "StatsService"]
  },
  "policy": {
     "levels": {
        "0": {
          "handshake": 4,
          "connIdle": 300,
          "uplinkOnly": 2,
          "downlinkOnly": 5,
          "bufferSize": 4,
          "statsUserUplink": true,
          "statsUserDownlink": true
        }
     },
     "system": {
        "statsInboundUplink": true,
        "statsInboundDownlink": true,
        "statsOutboundUplink": true,
        "statsOutboundDownlink": true
     }
    },
"inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 10086,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "tag": "api"
    },
    {
      "tag": "Vless-TCP-TLS-Vision",
      "port": 443,
      "protocol": "vless",
      "streamSettings": {
        "network": "tcp",
        "security": "tls",
        "tlsSettings": {
          "certificates": [
            {
              "ocspStapling": 3600,
              "certificateFile": "/etc/letsencrypt/live/EXAMPLE.COM/fullchain.pem",
              "keyFile": "/etc/letsencrypt/live/EXAMPLE.COM/privkey.pem"
            }
          ],
          "minVersion": "1.2",
          "cipherSuites": "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256:TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256:TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
          "alpn": [
            "h2",
            "http/1.1"
          ]
        }
      },
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      },
      "settings": {
        "clients": [
          {
            "id": "dbfgb6e2-7718-5a6c-b4d3-5e8h92cesbff",
            "email": "test1@test.com",
            "flow": "xtls-rprx-vision",
            "level": 0
          },
          {
            "id": "j1831db5-0f8f-6d2d-eaav-d41f0klgd221",
            "email": "test2@test.com",
            "flow": "xtls-rprx-vision",
            "level": 0
          }
        ],
        "decryption": "none",
        "fallbacks": [
          {
            "path": "/vlws",
            "dest": "@vless-ws",
            "xver": 2
          }
        ]
      }
    },
    {
      "tag": "vmess-ws",
      "listen": "@vmess-ws",
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "dbfgb6e2-7718-5a6c-b4d3-5e8h92cesbff",
            "email": "test1@test.com",
            "level": 0
          },
          {
            "id": "j1831db5-0f8f-6d2d-eaav-d41f0klgd221",
            "email": "test2@test.com",
            "level": 0
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "security": "none",
        "wsSettings": {
          "acceptProxyProtocol": true,
          "path": "/vmws"
        }
      },
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      }
    }
  ],
  "routing": {
    "domainStrategy": "AsIs",
    "domainMatcher": "hybrid",
    "strategy": "rules",
    "settings": {
      "rules": [
        {
          "inboundTag": ["api"],
          "outboundTag": "api",
          "type": "field"
        }

      ]
    }
  }
}

But when I use for example xray api statssys --server=127.0.0.1:10086 i get this error: failed to dial 127.0.0.1:10086 Somehow, I cannot connect to the API service. When I use ss -lptn 'sport = :10086' it shows that indeed Xray is listening on port 10086. I used different ports and still got the same error. I also used the bash script according to the documentation and still the same error show up

I wanted to know if my config is wrong or is this a bug?!

alisalmani commented 1 year ago

Hi , add each client tag like

"email": "general@vless-tcp-xtls", "level": 0

and restart vps

PouriaMzn commented 1 year ago

Hi , add each client tag like

"email": "general@vless-tcp-xtls", "level": 0

and restart vps

Thanks for your answer. Actually, I'm using email and level for the clients, I updated my original post so you could see better what's going on. I'm using a multi-protocol and multi-user on a single port in my server according to this wonderful example, but I still get failed to dial 127.0.0.1:10086 error.

alisalmani commented 1 year ago

check this command xray api statsquery --server=127.0.0.1:10086 -pattern ''

PouriaMzn commented 1 year ago

ss -lptn 'sport = :10086'

still get the same error

alisalmani commented 1 year ago

this config worked for me { "log": { "access": "/var/log/xray/access.log", "error": "/var/log/xray/error.log", "loglevel": "warning" }, "api": { "services": [ "HandlerService", "LoggerService", "StatsService" ], "tag": "api" }, "stats": {}, "policy": { "levels": { "0": { "statsUserUplink": true, "statsUserDownlink": true } }, "system": { "statsInboundUplink": true, "statsInboundDownlink": true, "statsOutboundUplink": true, "statsOutboundDownlink": true } }, "inbounds": [ { "listen": "127.0.0.1", "port": 10085, "protocol": "dokodemo-door", "settings": { "address": "127.0.0.1" }, "tag": "api", "sniffing": null }, { "tag": "Vless-TCP-XTLS", "port": 443, "protocol": "vless", "settings": { "clients": [ { "email": "general@vless-tcp-xtls", "id": "91c2df6b-02cf-4067-b9b5-526aabb6bd03", "flow": "xtls-rprx-direct", "level": 0 }, { "email": "v1@vless-tcp-xtls", "id": "2b0927a1-e309-4e52-aa41-26ee8e46b2a9", "flow": "xtls-rprx-direct", "level": 0 }, { "email": "v2@vless-tcp-xtls", "id": "35be2e9d-94ef-404d-b3e4-15c75f502a33", "flow": "xtls-rprx-direct", "level": 0 },

    ],
    "decryption": "none",
    "fallbacks": [
      {
        "dest": 60000,
        "alpn": "",
        "xver": 1
      },
      {
        "dest": 60001,
        "alpn": "h2",
        "xver": 1
      },
      {
        "dest": 60002,
        "path": "/c78e/",
        "xver": 1
      }
    ]
  },
  "streamSettings": {
    "network": "tcp",
    "security": "xtls",
    "xtlsSettings": {
      "minVersion": "1.2",
      "certificates": [
        {
          "certificateFile": "/usr/local/etc/xray/self_signed_cert.pem",
          "keyFile": "/usr/local/etc/xray/self_signed_key.pem"
        },
        {
          "certificateFile": "/ssl/xray.crt",
          "keyFile": "/ssl/xray.key"
        }
      ]
    }
  },
  "sniffing": {
    "enabled": true,
    "destOverride": [
      "http",
      "tls"
    ]
  }
},
{
  "port": 60002,
  "listen": "127.0.0.1",
  "protocol": "vless",
  "settings": {
    "clients": [
      {
        "email": "general@vless-tcp-xtls",
        "id": "91c2df6b-02cf-4067-b9b5-526aabb6bd03",
        "flow": "xtls-rprx-direct",
        "level": 0
      }
    ],
    "decryption": "none"
  },
  "streamSettings": {
    "network": "ws",
    "security": "none",
    "wsSettings": {
      "acceptProxyProtocol": true,
      "path": "/c78e/"
    }
  }
}

], "outbounds": [ { "protocol": "freedom" } ], "routing": { "rules": [ { "inboundTag": [ "api" ], "outboundTag": "api", "type": "field" } ], "domainStrategy": "AsIs" } }

check this and then add other protocols

houmie commented 1 year ago

Hi @alisalmani

Thank you for the example. That works perfectly on the server.

1) Is it possible to query how much traffic your user with the email v1@vless-tcp-xtls has utilised? How can I do that? 2) I can run xray api statsquery --server=127.0.0.1:10085 and xray api statssys --server=127.0.0.1:10085 on my server. But xray api stats --server=127.0.0.1:10085 fails with the error: failed to get stats: rpc error: code = Unknown desc = app/stats/command: not found. Do you know why?

Thanks

alisalmani commented 1 year ago

hi @houmie use this for all users traffic: xray api statsquery --server=127.0.0.1:10085 -pattern '' now i can not check it but maybe it work xray api statsquery --server=127.0.0.1:10085 'v1@vless-tcp-xtls'

houmie commented 1 year ago

Hi @alisalmani Thank you so much. Yes, xray api statsquery --server=127.0.0.1:10085 -pattern general@vless-tcp-xtls works well.

I have one more question for you. Is there a way to measure the traffic on the client as well?

I have created this client config, but it times out trying to connect to dokodemo-door at 127.0.0.1:10085 on iPhone. I wonder why.

{
  "api": {
    "services": [
      "HandlerService",
      "LoggerService",
      "StatsService"
    ],
    "tag": "api"
  },
  "stats": {},
  "policy": {
    "levels": {
      "0": {
        "statsUserUplink": true,
        "statsUserDownlink": true,
        "handshake": 3,
        "connIdle": 180
      }
    },
    "system": {
      "statsInboundUplink": true,
      "statsInboundDownlink": true,
      "statsOutboundUplink": true,
      "statsOutboundDownlink": true
    }
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 10085,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "tag": "api",
      "sniffing": null
    },
    {
      "listen": "[::1]",
      "port": 8080,
      "protocol": "socks",
      "settings": {
        "auth": "noauth",
        "udp": true
      },
      "sniffing": {
        "destOverride": [
          "http",
          "tls"
        ],
        "enabled": true,
        "excludedDomains": [],
        "metadataOnly": false,
        "routeOnly": false
      },
      "tag": "socks-in"
    }
  ],
  "outbounds": [
    {
      "protocol": "vless",
      "settings": {
        "vnext": [
          {
            "address": "xxx.xxx.xxx.xx",
            "port": 443,
            "users": [
              {
                "encryption": "none",
                "flow": "xtls-rprx-vision",
                "id": "8652b34d-a236-4eca-8a08-b30ea4e63cba"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "tcp",
        "realitySettings": {
          "fingerprint": "chrome",
          "publicKey": "eGZ4cJLCFo8gqCkFGuwxCRVx8FE3R2vh__uqCFZg6RM",
          "serverName": "www.google-analytics.com",
          "shortId": "1ad99ba959dec1a9",
          "show": false,
          "spiderX": ""
        },
        "security": "reality",
        "tcpSettings": {
          "header": {
            "type": "none"
          }
        }
      },
      "tag": "proxy"
    },
    {
      "protocol": "freedom",
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "tag": "block"
    }
  ],
  "routing": {
    "balancers": [],
    "domainMatcher": "hybrid",
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api"
      },
      {
        "__enabled__": true,
        "__id__": "E88ACF9A-E85D-4C03-B2BF-43D0513613F3",
        "__name__": "Rule_E88ACF9A-E85D-4C03-B2BF-43D0513613F3",
        "domainMatcher": "hybrid",
        "network": "udp,tcp,",
        "outboundTag": "block",
        "protocol": [
          "bittorrent"
        ],
        "type": "field"
      }
    ]
  }
}
alisalmani commented 1 year ago

Hi @houmie you do not need api part in client side it's work only on server remove this part from your client config { "listen": "127.0.0.1", "port": 10085, "protocol": "dokodemo-door", "settings": { "address": "127.0.0.1" }, "tag": "api", "sniffing": null },

houmie commented 1 year ago

Hi @alisalmani
I see. Thank you. I have removed it as you suggested but it still fails.

I'm using this official Xray wrapper for iOS. There is this Go function QueryStats() that is supposed to show the traffic stats.

I have tried everything, but it fails on this line with context deadline exceeded when it tries to connect. The maintainer of that wrapper is sure that this function is working. So it must be something with my configuration.

Not sure, if this is in your expertise field, I would love to hear your opinion. :-) But please don't worry if you don't know the answer.

Many Thanks

Mahyar24 commented 11 months ago

@PouriaMzn, In my case, what stopped me from API connection was this rule:

{
        "ip": [
                    "geoip:private"
              ],
    "outboundTag": "blocked",
        "type": "field",
        "tag": "private"
}