From 446cc3f9a7a9300c493355c252d30e44886e0bdf Mon Sep 17 00:00:00 2001 From: "arraykeys@gmail.com" Date: Tue, 6 Mar 2018 17:37:23 +0800 Subject: [PATCH] Signed-off-by: arraykeys@gmail.com --- README_ZH.md | 9 +++++++-- config.go | 2 +- services/sps.go | 30 +++++++++++++++++------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/README_ZH.md b/README_ZH.md index 8c0d7a8..77798eb 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -124,7 +124,8 @@ Proxy是golang实现的高性能http,https,websocket,tcp,udp,socks5代理服务 - [6.2 HTTP(S)转HTTP(S)+SOCKS5](#62-https转httpssocks5) - [6.3 SOCKS5转HTTP(S)+SOCKS5](#63-socks5转httpssocks5) - [6.4 链式连接](#64-链式连接) - - [6.5 查看帮助](#65-查看帮助) + - [6.5 监听多个端口](#65-监听多个端口) + - [6.6 查看帮助](#66-查看帮助) ### Fast Start 提示:所有操作需要root权限. @@ -725,7 +726,11 @@ vps02:3.3.3.3 完成。 -#### **6.5 查看帮助** +#### **6.5 监听多个端口** +一般情况下监听一个端口就可以,不过如果作为反向代理需要同时监听80和443两个端口,那么-p参数是支持的, +格式是:`-p 0.0.0.0:80,0.0.0.0:443`,多个绑定用逗号分隔即可。 + +#### **6.6 查看帮助** `./proxy help sps` diff --git a/config.go b/config.go index bf3a593..04be4b2 100755 --- a/config.go +++ b/config.go @@ -195,7 +195,7 @@ func initConfig() (err error) { spsArgs.Timeout = sps.Flag("timeout", "tcp timeout milliseconds when connect to real server or parent proxy").Short('i').Default("2000").Int() spsArgs.ParentType = sps.Flag("parent-type", "parent protocol type ").Short('T').Enum("tls", "tcp", "kcp") spsArgs.LocalType = sps.Flag("local-type", "local protocol type ").Default("tcp").Short('t').Enum("tls", "tcp", "kcp") - spsArgs.Local = sps.Flag("local", "local ip:port to listen").Short('p').Default(":33080").String() + spsArgs.Local = sps.Flag("local", "local ip:port to listen,multiple address use comma split,such as: 0.0.0.0:80,0.0.0.0:443").Short('p').Default(":33080").String() spsArgs.KCPKey = sps.Flag("kcp-key", "key for kcp encrypt/decrypt data").Short('B').Default("encrypt").String() spsArgs.KCPMethod = sps.Flag("kcp-method", "kcp encrypt/decrypt method").Short('M').Default("3des").String() spsArgs.ParentServiceType = sps.Flag("parent-service-type", "parent service type ").Short('S').Enum("http", "socks") diff --git a/services/sps.go b/services/sps.go index d1d61b0..5643235 100644 --- a/services/sps.go +++ b/services/sps.go @@ -68,20 +68,24 @@ func (s *SPS) Start(args interface{}) (err error) { log.Printf("use %s %s parent %s", *s.cfg.ParentType, *s.cfg.ParentServiceType, *s.cfg.Parent) s.InitService() - host, port, _ := net.SplitHostPort(*s.cfg.Local) - p, _ := strconv.Atoi(port) - sc := utils.NewServerChannel(host, p) - if *s.cfg.LocalType == TYPE_TCP { - err = sc.ListenTCP(s.callback) - } else if *s.cfg.LocalType == TYPE_TLS { - err = sc.ListenTls(s.cfg.CertBytes, s.cfg.KeyBytes, s.callback) - } else if *s.cfg.LocalType == TYPE_KCP { - err = sc.ListenKCP(*s.cfg.KCPMethod, *s.cfg.KCPKey, s.callback) + for _, addr := range strings.Split(*s.cfg.Local, ",") { + if addr != "" { + host, port, _ := net.SplitHostPort(*s.cfg.Local) + p, _ := strconv.Atoi(port) + sc := utils.NewServerChannel(host, p) + if *s.cfg.LocalType == TYPE_TCP { + err = sc.ListenTCP(s.callback) + } else if *s.cfg.LocalType == TYPE_TLS { + err = sc.ListenTls(s.cfg.CertBytes, s.cfg.KeyBytes, s.callback) + } else if *s.cfg.LocalType == TYPE_KCP { + err = sc.ListenKCP(*s.cfg.KCPMethod, *s.cfg.KCPKey, s.callback) + } + if err != nil { + return + } + log.Printf("%s http(s)+socks proxy on %s", s.cfg.Protocol(), (*sc.Listener).Addr()) + } } - if err != nil { - return - } - log.Printf("%s http(s)+socks proxy on %s", s.cfg.Protocol(), (*sc.Listener).Addr()) return }