<img width="160" height="160" src="https://github.com/Gozargah/Marzban-docs/raw/master/screenshots/logo-light.png">
Marzban
Unified GUI Censorship Resistant Solution Powered by <a href="https://github.com/XTLS/Xray-core">Xray</a>
<a href="#">
<img src="https://img.shields.io/github/actions/workflow/status/gozargah/marzban/build.yml?style=flat-square" />
</a>
<a href="https://hub.docker.com/r/gozargah/marzban" target="_blank">
<img src="https://img.shields.io/docker/pulls/gozargah/marzban?style=flat-square&logo=docker" />
</a>
<a href="#">
<img src="https://img.shields.io/github/license/gozargah/marzban?style=flat-square" />
</a>
<a href="https://t.me/gozargah_marzban" target="_blank">
<img src="https://img.shields.io/badge/telegram-group-blue?style=flat-square&logo=telegram" />
</a>
<a href="#">
<img src="https://img.shields.io/badge/twitter-commiunity-blue?style=flat-square&logo=twitter" />
</a>
<a href="#">
<img src="https://img.shields.io/github/stars/gozargah/marzban?style=social" />
</a>
<a href="https://github.com/Gozargah/Marzban/raw/v0.8.4/README.md">
English
</a>
/
<a href="https://github.com/Gozargah/Marzban/raw/v0.8.4/README-fa.md">
فارسی
</a>
/
Marzban(Marzban一词源自波斯语,意为“边境警卫”,发音为 /mærz'ban/)是一个代理管理工具,提供简单易用的用户界面,可管理数百个代理账户,由 Xray-core 提供支持,使用 Python 和 Reactjs 构建。
Marzban 是一个用户友好、功能丰富且可靠的工具。它让您可以为用户创建不同的代理,无需进行任何复杂的配置。通过其内置的 Web 界面,您可以监视、修改和限制用户。
运行以下命令以使用 SQLite 数据库安装 Marzban。
sudo bash -c "$(curl -sL https://github.com/Gozargah/Marzban-scripts/raw/master/marzban.sh)" @ install
运行以下命令以使用 MySQL 数据库安装 Marzban。
sudo bash -c "$(curl -sL https://github.com/Gozargah/Marzban-scripts/raw/master/marzban.sh)" @ install --database mysql
运行以下命令以使用 MariaDB 数据库安装 Marzban。
sudo bash -c "$(curl -sL https://github.com/Gozargah/Marzban-scripts/raw/master/marzban.sh)" @ install --database mariadb
Once the installation is complete:
Ctrl+C/opt/marzban/opt/marzban/.env (refer to configurations section to see variables)/usr/lib/marzbanhttps://YOUR_DOMAIN:8000/dashboard/ (replace YOUR_DOMAIN with your actual domain)user@serverip with your actual SSH username and server IP and Run the command below:ssh -L 8000:localhost:8000 user@serverip
Finally, you can enter the following link in your browser to access your Marzban dashboard:
http://localhost:8000/dashboard/
You will lose access to the dashboard as soon as you close the SSH terminal. Therefore, this method is recommended only for testing purposes.
Next, you need to create a sudo admin for logging into the Marzban dashboard by the following command
marzban cli admin create --sudo
That's it! You can login to your dashboard using these credentials
To see the help message of the Marzban script, run the following command
marzban --help
If you are eager to run the project using the source code, check the section below
在您的机器上安装 xray
您可以使用 Xray-install 脚本进行安装:
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
克隆项目并安装依赖项。
您需要 Python>=3.8 版本。
git clone https://github.com/Gozargah/Marzban.git
cd Marzban
wget -qO- https://bootstrap.pypa.io/get-pip.py | python3 -
python3 -m pip install -r requirements.txt
另外,为了拥有一个隔离的环境,您可以使用 Python Virtualenv。
然后运行以下命令运行数据库迁移脚本:
alembic upgrade head
现在开始配置:
复制 .env.example 文件,查看并使用文本编辑器(如nano)进行编辑。
您可能想要修改管理员凭据。
cp .env.example .env
nano .env
请查看配置部分以获取更多信息。
最终,使用以下命令启动应用程序:
python3 main.py
也可使用 linux systemctl 启动:
systemctl enable /var/lib/marzban/marzban.service
systemctl start marzban
配合 nginx 使用:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location ~* /(dashboard|statics|sub|api|docs|redoc|openapi.json) {
proxy_pass http://0.0.0.0:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# xray-core ws-path: /
# client ws-path: /marzban/me/2087
#
# 所有流量通过 443 端口进行代理,然后分发至真正的 xray 端口(2087、2088 等等)。
# 路径中的 “/marzban” 可以改为任意合法 URL 字符.
#
# /${path}/${username}/${xray-port}
location ~* /marzban/.+/(.+)$ {
proxy_redirect off;
proxy_pass http://127.0.0.1:$1/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
或
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name marzban.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location / {
proxy_pass http://0.0.0.0:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
默认情况下,应用将在 http://localhost:8000/dashboard 上运行。您可以通过更改 UVICORN_HOST 和 UVICORN_PORT 环境变量来进行配置。
您可以使用环境变量或将其放置在
env或.env文件中来设置以下设置。
| 变量 | 描述 |
|---|---|
| SUDO_USERNAME | 管理员用户名(默认: admin) |
| SUDO_PASSWORD | 管理员密码(默认: admin) |
| SQLALCHEMY_DATABASE_URL | 数据库文档(SQLAlchemy's docs) |
| UVICORN_HOST | 绑定应用程序到此主机(默认为 0.0.0.0) |
| UVICORN_PORT | 绑定应用程序到此端口(默认为 8000) |
| UVICORN_UDS | 将应用程序绑定到一个 UNIX 域套接字 |
| UVICORN_SSL_CERTFILE | SSL 证书文件路径 |
| UVICORN_SSL_KEYFILE | SSL 密钥文件路径 |
| UVICORN_SSL_CA_TYPE | 授权 SSL 证书的类型。使用“private”来测试自签名 CA(默认值:public) |
| XRAY_JSON | Xray 的 json 配置文件路径(默认: xray_config.json) |
| XRAY_EXECUTABLE_PATH | Xray 的执行程序路径: /usr/local/bin/xray) |
| XRAY_ASSETS_PATH | Xray 的资源目录: /usr/local/share/xray) |
| XRAY_SUBSCRIPTION_URL_PREFIX | 订阅URL的前缀 |
| XRAY_FALLBACKS_INBOUND_TAG | 包含 fallbacks 的入站标记, 在您需要使用 fallbacks 配置此项 |
| XRAY_EXCLUDE_INBOUND_TAGS | 不需要此应用程序管理或在链接中包含的入站标记 |
| CLASH_SUBSCRIPTION_TEMPLATE | 将用于生成冲突配置的模板(默认值:clash/default.yml) |
| SUBSCRIPTION_PAGE_TEMPLATE | 用于生成订阅信息页面的模板(默认:subscription/index.html) |
| HOME_PAGE_TEMPLATE | 诱饵页面模板(默认:home/index.html) |
| TELEGRAM_API_TOKEN | Telegram bot API 令牌(可以从 @botfather 获取) |
| TELEGRAM_ADMIN_ID | 管理员的 Telegram ID(可以使用 @userinfobot 查找您的 ID) |
| TELEGRAM_PROXY_URL | 在代理下运行 Telegram bot。 |
| JWT_ACCESS_TOKEN_EXPIRE_MINUTES | Access Tokens 的过期时间,以分钟为单位,0 表示无限期(默认为 1440 分钟) |
| DOCS | API 文档是否应该在 /docs 和 /redoc 上提供(默认为 False |
| DEBUG | Debug mode for development (default: False) |
| WEBHOOK_ADDRESS | Webhook address to send notifications to. Webhook notifications will be sent if this value was set. |
| WEBHOOK_SECRET | Webhook secret will be sent with each request as x-webhook-secret in the header (default: None) |
| NUMBER_OF_RECURRENT_NOTIFICATIONS | How many times to retry if an error detected in sending a notification (default: 3) |
| RECURRENT_NOTIFICATIONS_TIMEOUT | Timeout between each retry if an error detected in sending a notification in seconds (default: 180) |
| NOTIFY_REACHED_USAGE_PERCENT | At which percentage of usage to send the warning notification (default: 80) |
| NOTIFY_DAYS_LEFT | When to send warning notifaction about expiration (default: 3) |
| USERS_AUTODELETE_DAYS | Delete expired (and optionally limited users) after this many days (Negative values disable this feature, default: -1) |
| USER_AUTODELETE_INCLUDE_LIMITED_ACCOUNTS | Weather to include limited accounts in the auto-delete feature (default: False) |
| USE_CUSTOM_JSON_DEFAULT | Enable custom JSON config for ALL supported clients (default: False) |
| USE_CUSTOM_JSON_FOR_V2RAYNG | Enable custom JSON config only for V2rayNG (default: False) |
| USE_CUSTOM_JSON_FOR_STREISAND | Enable custom JSON config only for Streisand (default: False) |
| USE_CUSTOM_JSON_FOR_V2RAYN | Enable custom JSON config only for V2rayN (default: False) |
$ claude mcp add Marzban \
-- python -m otcore.mcp_server <graph>