add https proto for reverse proxy

This commit is contained in:
Maodanping
2016-06-13 22:19:24 +08:00
parent 740fb05b21
commit f3876d69bb
6 changed files with 272 additions and 6 deletions

View File

@@ -115,7 +115,7 @@ func LoadConf(confFile string) (err error) {
proxyClient.Type = "tcp"
typeStr, ok := section["type"]
if ok {
if typeStr != "tcp" && typeStr != "http" {
if typeStr != "tcp" && typeStr != "http" && typeStr != "https" {
return fmt.Errorf("Parse ini file error: proxy [%s] type error", proxyClient.Name)
}
proxyClient.Type = typeStr

View File

@@ -32,6 +32,7 @@ var (
BindAddr string = "0.0.0.0"
BindPort int64 = 7000
VhostHttpPort int64 = 0 // if VhostHttpPort equals 0, don't listen a public port for http
VhostHttpsPort int64 = 0 // if VhostHttpsPort equals 0, don't listen a public port for http
DashboardPort int64 = 0 // if DashboardPort equals 0, dashboard is not available
LogFile string = "console"
LogWay string = "console" // console or file
@@ -40,7 +41,8 @@ var (
HeartBeatTimeout int64 = 90
UserConnTimeout int64 = 10
VhostMuxer *vhost.HttpMuxer
VhostHttpMuxer *vhost.HttpMuxer
VhostHttpsMuxer *vhost.HttpsMuxer
ProxyServers map[string]*ProxyServer = make(map[string]*ProxyServer) // all proxy servers info and resources
ProxyServersMutex sync.RWMutex
)
@@ -91,6 +93,14 @@ func loadCommonConf(confFile string) error {
VhostHttpPort = 0
}
tmpStr, ok = conf.Get("common", "vhost_https_port")
if ok {
VhostHttpsPort, _ = strconv.ParseInt(tmpStr, 10, 64)
} else {
VhostHttpsPort = 0
}
vhost.VhostHttpsPort = VhostHttpsPort
tmpStr, ok = conf.Get("common", "dashboard_port")
if ok {
DashboardPort, _ = strconv.ParseInt(tmpStr, 10, 64)
@@ -135,7 +145,7 @@ func loadProxyConf(confFile string) (proxyServers map[string]*ProxyServer, err e
proxyServer.Type, ok = section["type"]
if ok {
if proxyServer.Type != "tcp" && proxyServer.Type != "http" {
if proxyServer.Type != "tcp" && proxyServer.Type != "http" && proxyServer.Type != "https" {
return proxyServers, fmt.Errorf("Parse conf error: proxy [%s] type error", proxyServer.Name)
}
} else {
@@ -179,6 +189,23 @@ func loadProxyConf(confFile string) (proxyServers map[string]*ProxyServer, err e
proxyServer.CustomDomains[i] = strings.ToLower(strings.TrimSpace(domain)) + suffix
}
}
} else if proxyServer.Type == "https" {
// for https
domainStr, ok := section["custom_domains"]
if ok {
var suffix string
if VhostHttpsPort != 443 {
suffix = fmt.Sprintf(":%d", VhostHttpsPort)
}
proxyServer.CustomDomains = strings.Split(domainStr, ",")
if len(proxyServer.CustomDomains) == 0 {
return proxyServers, fmt.Errorf("Parse conf error: proxy [%s] custom_domains must be set when type equals http", proxyServer.Name)
}
for i, domain := range proxyServer.CustomDomains {
proxyServer.CustomDomains[i] = strings.ToLower(strings.TrimSpace(domain)) + suffix
}
log.Info("proxyServer: %+v", proxyServer.CustomDomains)
}
}
proxyServers[proxyServer.Name] = proxyServer
}

View File

@@ -100,7 +100,15 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
p.listeners = append(p.listeners, l)
} else if p.Type == "http" {
for _, domain := range p.CustomDomains {
l, err := VhostMuxer.Listen(domain)
l, err := VhostHttpMuxer.Listen(domain)
if err != nil {
return err
}
p.listeners = append(p.listeners, l)
}
} else if p.Type == "https" {
for _, domain := range p.CustomDomains {
l, err := VhostHttpsMuxer.Listen(domain)
if err != nil {
return err
}