Skip to content

xuexb/dyups

Repository files navigation

dyups

OpenResty Dynamic Upstream

前端小武动态化转发服务,配合泛域名可轻松部署一个独立域名服务。

Features

  • MySQL 数据持久化
  • Agent 同步
  • 多机部署
  • Upstream 动态加载
  • Upstream 负载均衡
  • Upstream 支持域名解析(解析缓存1天)
  • Token 鉴权
    • Cookie - x_dyups_token=value
    • GET param - token=value
    • Request Header - x-dyups-token=value
  • 响应 Headers
    • x-dyups-target - 当前响应服务的目标地址(IP/域名+端口)
  • 向上游应用服务透传 Headers
    • host - 127.0.0.1 ,用于破解备案限制
    • x-dyups - true
    • x-dyups-host - 用户真实 Host
    • x-dyups-scheme - 用户访问的协议
    • x-dyups-ip - 用户真实 IP

API

Get data

curl -H 'x-dyups-token: token' dyups/api/all
curl -H 'x-dyups-token: token' dyups/api/test.xuexb.com

Add

curl -H 'x-dyups-token: token' \
    -X POST \
    -d '[{"address":"127.0.0.1","port":8080}]' \
    dyups/api/test.xuexb.com

# proxy timeout
curl -H 'x-dyups-token: token' \
    -X POST \
    -d '{"server":[{"address":"127.0.0.1","port":8080}],"timeout":5}' \
    dyups/api/test.xuexb.com

Remove

curl -H 'x-dyups-token: token' \
    -X DELETE \
    dyups/api/test.xuexb.com

Reload single agent

curl -H 'x-dyups-token: token' dyups/api/reload

Sync all agent

curl -H 'x-dyups-token: token' dyups/api/sync

SQL

SET NAMES utf8mb4;

DROP TABLE IF EXISTS `upstream`;
CREATE TABLE `upstream` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `domain` char(100) NOT NULL DEFAULT '',
  `server` text NOT NULL,
  `timeout` int(2) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `domain` (`domain`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


DROP TABLE IF EXISTS `agent`;
CREATE TABLE `agent` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `address` char(255) NOT NULL DEFAULT '',
  `remark` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

About

OpenResty Dynamic Upstream

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages