Gegegg GG
Gegegg GG

Reputation: 11

how to use api 3x-ui?

I have my own server on which I configure vless. I installed x3-ui and want to access the api. The official repository only has a config for nginx, which I used, but when I try to access the api I get the error "curl: (1) Unsupported HTTP version in response"

For Nginx (i took it from 3x-ui repository):

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Range $http_range;
    proxy_set_header If-Range $http_if_range; 
    proxy_redirect off;
    proxy_pass http://127.0.0.1:2053;
}

x3-ui json config:

{
  "log": {
    "access": "none",
    "dnsLog": false,
    "error": "",
    "loglevel": "warning",
    "maskAddress": ""
  },
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api"
      },
      {
        "type": "field",
        "outboundTag": "blocked",
        "ip": [
          "geoip:private",
          "ext:geoip_IR.dat:ir",
          "geoip:cn",
          "geoip:ru",
          "ext:geoip_VN.dat:vn",
          "geoip:es",
          "geoip:id",
          "geoip:ua",
          "geoip:tr",
          "geoip:br"
        ]
      },
      {
        "type": "field",
        "outboundTag": "blocked",
        "protocol": [
          "bittorrent"
        ]
      },
      {
        "type": "field",
        "outboundTag": "blocked",
        "domain": [
          "ext:geosite_IR.dat:malware",
          "ext:geosite_IR.dat:phishing",
          "ext:geosite_IR.dat:cryptominers",
          "ext:geosite_VN.dat:vn",
          "regexp:.*\\.vn$",
          "regexp:.*\\.cn$",
          "geosite:cn",
          "regexp:.*\\.xn--mgba3a4f16a$",
          "regexp:.*\\.ir$"
        ]
      },
      {
        "type": "field",
        "outboundTag": "direct",
        "domain": [
          "regexp:.*\\.ru",
          "geosite:category-ru"
        ]
      }
    ]
  },
  "dns": null,
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 62789,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "streamSettings": null,
      "tag": "api",
      "sniffing": null,
      "allocate": null
    },
    {
      "listen": null,
      "port": 16206,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "email": "ziigcc1i",
            "flow": "",
            "id": "d33b2c6e-b5c5-45cd-9f97-4af8690f5840"
          }
        ],
        "decryption": "none",
        "fallbacks": []
      },
      "streamSettings": {
        "network": "tcp",
        "realitySettings": {
          "dest": "yahoo.com:443",
          "maxClient": "",
          "maxTimediff": 0,
          "minClient": "",
          "privateKey": "uDbl1l7mVLvjNhpqPik3699-_QJFcp1Qoa4-KlYPt1Y",
          "serverNames": [
            "yahoo.com",
            "www.yahoo.com"
          ],
          "shortIds": [
            "658a9003",
            "1060eeeba0",
            "dcf27c8af061",
            "7aaa",
            "0d7cae",
            "1cb14e7e20c3acf7",
            "1e",
            "7549f51728d9cc"
          ],
          "show": false,
          "xver": 0
        },
        "security": "reality",
        "tcpSettings": {
          "acceptProxyProtocol": false,
          "header": {
            "type": "none"
          }
        }
      },
      "tag": "inbound-16206",
      "sniffing": {
        "enabled": false,
        "destOverride": [
          "http",
          "tls",
          "quic",
          "fakedns"
        ],
        "metadataOnly": false,
        "routeOnly": false
      },
      "allocate": {
        "strategy": "always",
        "refresh": 5,
        "concurrency": 3
      }
    }
  ],
  "outbounds": [
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIP",
        "redirect": "",
        "noises": []
      }
    },
    {
      "tag": "blocked",
      "protocol": "blackhole",
      "settings": {}
    }
  ],
  "transport": null,
  "policy": {
    "levels": {
      "0": {
        "statsUserDownlink": true,
        "statsUserUplink": true
      }
    },
    "system": {
      "statsInboundDownlink": true,
      "statsInboundUplink": true,
      "statsOutboundDownlink": true,
      "statsOutboundUplink": true
    }
  },
  "api": {
    "tag": "api",
    "services": [
      "HandlerService",
      "LoggerService",
      "StatsService"
    ]
  },
  "stats": {},
  "reverse": null,
  "fakedns": null,
  "observatory": null,
  "burstObservatory": null
}

Upvotes: 1

Views: 1774

Answers (2)

Esmaeil Taheri
Esmaeil Taheri

Reputation: 3

You can use 3x-ui php sdk : https://github.com/es-taheri/3x-ui Example:

use XUI\Xray\Inbound\Protocols\Vmess\Vmess;
use XUI\Xui;

require_once __DIR__.'/vendor/autoload.php';
$xui = new Xui($xui_host, $xui_port, $xui_path, $xui_ssl);
$result = $xui->login($username, $password);
@$response = $result->repsonse;
if ($result->ok && $response->success) {
    $xui_inbound = $xui->xray->inbound;
    $config = new Vmess();
    $config->settings->add_client();
    $config->stream_settings->ws_settings(false, '/3x-ui');
    $result = $xui_inbound->add($config, 'Test 3x-ui', 100 * Xui::UNIT_GIGABYTE, 86400);
    @$response = $result->repsonse;
    if ($result->ok && $response->success) {
        $inbound_id = $response->obj->id;
        var_dump("Inbound added : #$inbound_id");
    } else {
        $error = $result->error ?? $response->msg;
        var_dump("Add inbound failed! (Error: $error)");
    }
} else {
    $error = $result->error ?? $response->msg;
    var_dump("Login failed! (Error: $error)");
}

Upvotes: 0

Alice Teplyakova
Alice Teplyakova

Reputation: 1

Disable embedded tls (remove any cert paths for web panel) Set listen ip/host to 127.0.0.1/localhost Check listen port for web panel (2053), ping it from localhost

Upvotes: 0

Related Questions