Marzban

Marzban

多协议代理管理工具 支持多节点部署和用户管理

Marzban是基于Xray-core的代理管理工具,提供Web界面支持多种协议如Vmess、VLESS、Trojan和Shadowsocks。具备多节点支持、流量和到期限制、订阅链接生成等功能,可管理大量代理账户。集成Telegram机器人和命令行界面,支持多语言,是一个全面的代理管理解决方案。

Marzban代理管理XrayWeb UIAPIGithub开源项目
<p align="center"> <a href="https://github.com/gozargah/marzban" target="_blank" rel="noopener noreferrer"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://github.com/Gozargah/Marzban-docs/raw/master/screenshots/logo-dark.png"> <img width="160" height="160" src="https://github.com/Gozargah/Marzban-docs/raw/master/screenshots/logo-light.png"> </picture> </a> </p> <h1 align="center"/>Marzban</h1> <p align="center"> Unified GUI Censorship Resistant Solution Powered by <a href="https://github.com/XTLS/Xray-core">Xray</a> </p> <br/> <p align="center"> <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> </p> <p align="center"> <a href="./README.md"> English </a> / <a href="./README-fa.md"> فارسی </a> / <a href="./README-zh-cn.md"> 简体中文 </a> / <a href="./README-ru.md"> Русский </a> </p> <p align="center"> <a href="https://github.com/gozargah/marzban" target="_blank" rel="noopener noreferrer" > <img src="https://github.com/Gozargah/Marzban-docs/raw/master/screenshots/preview.png" alt="Marzban screenshots" width="600" height="auto"> </a> </p>

Table of Contents

Overview

Marzban (the Persian word for "border guard" - pronounced /mærz'ban/) is a proxy management tool that provides a simple and easy-to-use user interface for managing hundreds of proxy accounts powered by Xray-core and built using Python and Reactjs.

Why using Marzban?

Marzban is user-friendly, feature-rich and reliable. It lets you to create different proxies for your users without any complicated configuration. Using its built-in web UI, you are able to monitor, modify and limit users.

Features

  • Built-in Web UI
  • Fully REST API backend
  • Multiple Nodes support (for infrastructure distribution & scalability)
  • Supports protocols Vmess, VLESS, Trojan and Shadowsocks
  • Multi-protocol for a single user
  • Multi-user on a single inbound
  • Multi-inbound on a single port (fallbacks support)
  • Traffic and expiry date limitations
  • Periodic traffic limit (e.g. daily, weekly, etc.)
  • Subscription link compatible with V2ray (such as V2RayNG, OneClick, Nekoray, etc.), Clash and ClashMeta
  • Automated Share link and QRcode generator
  • System monitoring and traffic statistics
  • Customizable xray configuration
  • TLS and REALITY support
  • Integrated Telegram Bot
  • Integrated Command Line Interface (CLI)
  • Multi-language
  • Multi-admin support (WIP)

Installation guide

Run the following command

sudo bash -c "$(curl -sL https://github.com/Gozargah/Marzban-scripts/raw/master/marzban.sh)" @ install

Once the installation is complete:

  • You will see the logs that you can stop watching them by closing the terminal or pressing Ctrl+C
  • The Marzban files will be located at /opt/marzban
  • The configuration file can be found at /opt/marzban/.env (refer to configurations section to see variables)
  • The data files will be placed at /var/lib/marzban
  • You can access the Marzban dashboard by opening a web browser and navigating to http://YOUR_SERVER_IP:8000/dashboard/ (replace YOUR_SERVER_IP with the actual IP address of your server)

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

<details markdown="1"> <summary><h3>Manual install (advanced)</h3></summary>

Install xray on your machine

You can install it using Xray-install

bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install

Clone this project and install the dependencies (you need 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

Alternatively, to have an isolated environment you can use Python Virtualenv

Then run the following command to run the database migration scripts

alembic upgrade head

If you want to use marzban-cli, you should link it to a file in your $PATH, make it executable, and install the auto-completion:

sudo ln -s $(pwd)/marzban-cli.py /usr/bin/marzban-cli sudo chmod +x /usr/bin/marzban-cli marzban-cli completion install

Now it's time to configuration

Make a copy of .env.example file, take a look and edit it using a text editor like nano.

You probably like to modify the admin credentials.

cp .env.example .env nano .env

Check configurations section for more information

Eventually, launch the application using command below

python3 main.py

To launch with linux systemctl (copy marzban.service file to /var/lib/marzban/marzban.service)

systemctl enable /var/lib/marzban/marzban.service
systemctl start marzban

To use with 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|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
    #
    # All traffic is proxed through port 443, and send to the xray port(2087, 2088 etc.).
    # The '/marzban' in location regex path can changed any characters by yourself.
    #
    # /${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;
    }
}

or

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;
    }
}

By default the app will be run on http://localhost:8000/dashboard. You can configure it using changing the UVICORN_HOST and UVICORN_PORT environment variables.

</details>

Configuration

You can set settings below using environment variables or placing them in .env file.

VariableDescription
SUDO_USERNAMESuperuser's username
SUDO_PASSWORDSuperuser's password
SQLALCHEMY_DATABASE_URLDatabase URL (SQLAlchemy's docs)
UVICORN_HOSTBind application to this host (default: 0.0.0.0)
UVICORN_PORTBind application to this port (default: 8000)
UVICORN_UDSBind application to a UNIX domain socket
UVICORN_SSL_CERTFILESSL certificate file to have application on https
UVICORN_SSL_KEYFILESSL key file to have application on https
XRAY_JSONPath of Xray's json config file (default: xray_config.json)
XRAY_EXECUTABLE_PATHPath of Xray binary (default: /usr/local/bin/xray)
XRAY_ASSETS_PATHPath of Xray assets (default: /usr/local/share/xray)
XRAY_SUBSCRIPTION_URL_PREFIXPrefix of subscription URLs
XRAY_FALLBACKS_INBOUND_TAGTag of the inbound that includes fallbacks, needed in the case you're using fallbacks
XRAY_EXCLUDE_INBOUND_TAGSTags of the inbounds that shouldn't be managed and included in links by application
CUSTOM_TEMPLATES_DIRECTORYCustomized templates directory (default: app/templates)
CLASH_SUBSCRIPTION_TEMPLATEThe template that will be used for generating clash configs (default: clash/default.yml)
SUBSCRIPTION_PAGE_TEMPLATEThe template used for generating subscription info page (default: subscription/index.html)
HOME_PAGE_TEMPLATEDecoy page template (default: home/index.html)
TELEGRAM_API_TOKENTelegram bot API token (get token from @botfather)
TELEGRAM_ADMIN_IDNumeric Telegram ID of admin (use @userinfobot to found your ID)
TELEGRAM_PROXY_URLRun Telegram Bot over proxy
JWT_ACCESS_TOKEN_EXPIRE_MINUTESExpire time for the Access Tokens in minutes, 0 considered as infinite (default: 1440)
DOCSWhether API documents should be available on /docs and /redoc or not (default: False)
DEBUGDebug mode for development (default: False)
WEBHOOK_ADDRESSWebhook address to send notifications to. Webhook notifications will be sent if this value was set.
WEBHOOK_SECRETWebhook secret will be sent with each request as x-webhook-secret in the header (default: None)
NUMBER_OF_RECURRENT_NOTIFICATIONSHow many times to retry if an error detected in sending a notification (default: 3)
RECURRENT_NOTIFICATIONS_TIMEOUTTimeout between each retry if an error detected in sending a notification in seconds (default: 180)
NOTIFY_REACHED_USAGE_PERCENTAt which percentage of usage to send the warning notification (default: 80)
NOTIFY_DAYS_LEFTWhen to send warning notifaction about expiration (default: 3)
USERS_AUTODELETE_DAYSDelete expired (and optionally limited users) after this many days (Negative values disable this feature, default: -1)
USER_AUTODELETE_INCLUDE_LIMITED_ACCOUNTSWeather to include limited accounts in the auto-delete feature (default: False)
USE_CUSTOM_JSON_DEFAULTEnable custom JSON config for ALL supported clients (default: False)
USE_CUSTOM_JSON_FOR_V2RAYNGEnable custom JSON config only for V2rayNG (default: False)
USE_CUSTOM_JSON_FOR_STREISANDEnable custom JSON config only for Streisand (default: False)
USE_CUSTOM_JSON_FOR_V2RAYNEnable custom JSON config only for V2rayN (default: False)

API

Marzban provides a REST API that enables developers to interact with Marzban services programmatically. To view the API documentation in Swagger UI or ReDoc, set the configuration variable DOCS=True and navigate to the /docs and /redoc.

Backup

It's always a good idea to backup your Marzban files regularly to prevent data loss in case of system failures or accidental deletion. Here are the steps to backup Marzban:

  1. By default, all Marzban important files are saved in /var/lib/marzban (Docker versions). Copy the entire /var/lib/marzban directory to a backup location of your choice, such as an external hard drive or cloud storage.
  2. Additionally, make sure to backup your env file, which contains your configuration variables, and also, your Xray config file. If you installed Marzban using marzban-scripts (recommended installation approach), the env and other configurations should be inside /opt/marzban/ directory.

By following these steps, you can ensure that you have a backup of all your Marzban files and data, as well as your configuration variables and Xray configuration, in case you need to restore them in the future. Remember to update your backups regularly to keep them up-to-date.

Telegram Bot

Marzban comes with an integrated Telegram bot that can handle server management, user creation and removal, and send notifications. This bot can be easily enabled by following a few simple steps, and it provides a convenient way to interact with Marzban without having to log in to the server every time.

To enable Telegram Bot:

  1. set TELEGRAM_API_TOKEN to your bot's API Token
  2. set TELEGRAM_ADMIN_ID to your Telegram account's numeric ID, you can get your ID from @userinfobot

Marzban CLI

Marzban comes with an integrated CLI named marzban-cli which allows administrators to have direct interaction with it.

If you've installed Marzban using easy install script, you can access the cli commands by running

marzban cli [OPTIONS] COMMAND [ARGS]...

For more information, You can read Marzban CLI's documentation.

Marzban Node

The Marzban project introduces the Marzban-node, which revolutionizes infrastructure distribution. With Marzban-node, you can distribute your infrastructure across multiple locations, unlocking benefits such as redundancy, high availability, scalability, flexibility. Marzban-node empowers users to connect to different servers, offering them the flexibility to choose and connect to multiple servers instead of being limited to only one server. For more detailed information and installation instructions, please refer to the Marzban-node official documentation

Webhook notifications

You can set a webhook address and Marzban will send the notifications to that address.

the requests will be sent as a post request to the adress provided by WEBHOOK_ADDRESS with WEBHOOK_SECRET as x-webhook-secret in the headers.

Example request sent from Marzban:

Headers:
Host: 0.0.0.0:9000
User-Agent: python-requests/2.28.1
Accept-Encoding: gzip,

编辑推荐精选

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

下拉加载更多