|
|
@ -4,10 +4,11 @@ import (
|
|
|
|
"crypto/tls"
|
|
|
|
"crypto/tls"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
//"net/url"
|
|
|
|
"net/http/httputil"
|
|
|
|
"log"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"regexp"
|
|
|
|
"regexp"
|
|
|
|
//"path/filepath"
|
|
|
|
//"path/filepath"
|
|
|
@ -44,7 +45,7 @@ func initRouters(cfg conf) {
|
|
|
|
registerUwsgiHandler(rule, r)
|
|
|
|
registerUwsgiHandler(rule, r)
|
|
|
|
case "fastcgi":
|
|
|
|
case "fastcgi":
|
|
|
|
registerFastCGIHandler(rule, h.Docroot, r)
|
|
|
|
registerFastCGIHandler(rule, h.Docroot, r)
|
|
|
|
case "http":
|
|
|
|
case "reverse":
|
|
|
|
registerHTTPHandler(rule, r)
|
|
|
|
registerHTTPHandler(rule, r)
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
fmt.Printf("invalid type: %s\n", rule.Type)
|
|
|
|
fmt.Printf("invalid type: %s\n", rule.Type)
|
|
|
@ -62,7 +63,7 @@ func initRouters(cfg conf) {
|
|
|
|
registerUwsgiHandler(rule, router)
|
|
|
|
registerUwsgiHandler(rule, router)
|
|
|
|
case "fastcgi":
|
|
|
|
case "fastcgi":
|
|
|
|
registerFastCGIHandler(rule, l.Docroot, router)
|
|
|
|
registerFastCGIHandler(rule, l.Docroot, router)
|
|
|
|
case "http":
|
|
|
|
case "reverse":
|
|
|
|
registerHTTPHandler(rule, router)
|
|
|
|
registerHTTPHandler(rule, router)
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
fmt.Printf("invalid type: %s\n", rule.Type)
|
|
|
|
fmt.Printf("invalid type: %s\n", rule.Type)
|
|
|
@ -180,13 +181,19 @@ func registerHTTPHandler(r rule, router *mux.Router) {
|
|
|
|
switch r.Target.Type {
|
|
|
|
switch r.Target.Type {
|
|
|
|
case "unix":
|
|
|
|
case "unix":
|
|
|
|
addr = r.Target.Path
|
|
|
|
addr = r.Target.Path
|
|
|
|
|
|
|
|
u = newProxy(addr, r.URLPrefix)
|
|
|
|
case "http":
|
|
|
|
case "http":
|
|
|
|
addr = fmt.Sprintf("%s:%d", r.Target.Host, r.Target.Port)
|
|
|
|
addr = fmt.Sprintf("%s:%d", r.Target.Host, r.Target.Port)
|
|
|
|
|
|
|
|
u1 := &url.URL{
|
|
|
|
|
|
|
|
Scheme: "http",
|
|
|
|
|
|
|
|
Host: addr,
|
|
|
|
|
|
|
|
Path: r.Target.Path,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
u = httputil.NewSingleHostReverseProxy(u1)
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
fmt.Printf("invalid scheme: %s, only support unix, http", r.Target.Type)
|
|
|
|
fmt.Printf("invalid scheme: %s, only support unix, http", r.Target.Type)
|
|
|
|
os.Exit(-1)
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u = newProxy(addr, r.URLPrefix)
|
|
|
|
|
|
|
|
p := strings.TrimRight(r.URLPrefix, "/")
|
|
|
|
p := strings.TrimRight(r.URLPrefix, "/")
|
|
|
|
router.PathPrefix(r.URLPrefix).Handler(
|
|
|
|
router.PathPrefix(r.URLPrefix).Handler(
|
|
|
|
http.StripPrefix(p, u))
|
|
|
|
http.StripPrefix(p, u))
|
|
|
|