Total Pageviews

Monday 30 November 2015

协议复用的代理服务器 Switcher


Switcher 是一个代理服务器,可以在同一个端口实现不同协议的连接,该项目会自动检测客户端连接过来的协议。目前支持 HTTP(S) 和 SSH 在同一个端口运行。

使用参数:

$ ./switcher --help
Switcher 1.0.0
usage: switcher [options]
 
Options:
  --listen   <:80>            Server Listen Address
  --ssh      <127.0.0.1:22>   SSH Server Address
  --default  <127.0.0.1:8080>  Default Server Address
 
Examples:
  To serve SSH(127.0.0.1:22) and HTTP(127.0.0.1:8080) on port 80
  $ switcher
 
  To serve SSH(127.0.0.1:2222) and HTTPS(127.0.0.1:443) on port 443
  $ switcher --listen :443 --ssh 127.0.0.1:2222 --default 127.0.0.1:443
使用示例:

在 80 端口运行 switcher ,然后将 SSH 转到 127.0.0.1:22 ,将 HTTP 转到 Nginx on 127.0.0.1:8080
$ switcher --listen :80 --ssh 127.0.0.1:22 --default 127.0.0.1:8080

HTTP 测试:
$ curl -I http://my-server.local
HTTP/1.1 200 OK

SSH 测试:
$ ssh james@my-server.local -p 80

Password:


-----------------
Run SSH and HTTP(S) on the same port.

Switcher is a proxy server which accepts connections and proxies based on which protocol is detected.
Currently implemented is:
  • SSH
The use case is running HTTP(S) and SSH on the same port.

Usage

Download release or Build:
make
To get help:
$ ./switcher --help
Switcher 1.0.0
usage: switcher [options]

Options:
  --listen   <:80>            Server Listen Address
  --ssh      <127.0.0.1:22>   SSH Server Address
  --default  <127.0.0.1:8080>  Default Server Address

Examples:
  To serve SSH(127.0.0.1:22) and HTTP(127.0.0.1:8080) on port 80
  $ switcher

  To serve SSH(127.0.0.1:2222) and HTTPS(127.0.0.1:443) on port 443
  $ switcher --listen :443 --ssh 127.0.0.1:2222 --default 127.0.0.1:443

Example

Run switcher on HTTP port 80, proxy to SSH on 127.0.0.1:22 and Nginx on 127.0.0.1:8080
$ switcher --listen :80 --ssh 127.0.0.1:22 --default 127.0.0.1:8080
To test HTTP:
$ curl -I http://my-server.local
HTTP/1.1 200 OK
To test SSH
$ ssh james@my-server.local -p 80
Password:

Why not sslh

Switcher is heavily influenced by sslh. It started out as a learning exercise to discover how sslh worked and attempt an implementation in Go.
The result is useful in its own right through use of Go's interfaces for protocol matching (making adding new protocols trivial), and lightweight goroutines (instead of forking, which is more CPU intensive under load).
from https://github.com/jamescun/switcher