第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Golang ReverseProxy 與 Apache2 SNI/主機(jī)名錯(cuò)誤

Golang ReverseProxy 與 Apache2 SNI/主機(jī)名錯(cuò)誤

Go
楊__羊羊 2021-12-07 10:10:41
我正在用 Go 編寫(xiě)我自己的 ReverseProxy。ReverseProxy 應(yīng)該連接我的 go-webserver 和我的 apache2 webserver。但是當(dāng)我在另一個(gè) IP 地址上運(yùn)行我的反向代理時(shí),當(dāng)反向代理將請(qǐng)求發(fā)送到 apache 時(shí),我的 Apache2 網(wǎng)絡(luò)服務(wù)器在我的 apache 日志文件中出現(xiàn)以下錯(cuò)誤。"Hosname xxxx provided via sni and hostname xxxx2 provided via http are different"我的反向代理和 apache-webserver 在 https 上運(yùn)行。這里有一些代碼:func (p *Proxy) directorApache(req *http.Request) {    mainServer := fmt.Sprintf("%s:%d", Config.HostMain, Config.PortMain)    req.URL.Scheme = "https"    req.URL.Host = mainServer}func (p *Proxy) directorGo(req *http.Request) {    goServer := fmt.Sprintf("%s:%d", Config.GoHost, Config.GoPort)    req.URL.Scheme = "http"    req.URL.Host = goServer}func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {    fmt.Println(req.URL.Path)    if p.isGoRequest(req) {        fmt.Println("GO")        p.goProxy.ServeHTTP(rw, req)        return    }    p.httpProxy.ServeHTTP(rw, req)}func main() {    var configPath = flag.String("conf", "./configReverse.json", "Path to the Json config file.")    flag.Parse()    proxy := New(*configPath)    cert, err := tls.LoadX509KeyPair(Config.PathCert, Config.PathPrivateKey)    if err != nil {        log.Fatalf("server: loadkeys: %s", err)    }    config := tls.Config{InsecureSkipVerify: true, Certificates: []tls.Certificate{cert}}    listener, err := net.Listen("tcp",    net.JoinHostPort(proxy.Host, strconv.Itoa(proxy.Port)))    if err != nil {        log.Fatalf("server: listen: %s", err)    }    log.Printf("server: listening on %s")    proxy.listener = tls.NewListener(listener, &config)    serverHTTPS := &http.Server{        Handler:   proxy.mux,        TLSConfig: &config,    }    if err := serverHTTPS.Serve(proxy.listener); err != nil {        log.Fatal("SERVER ERROR:", err)    }}也許有人對(duì)這個(gè)問(wèn)題有想法。
查看完整描述

1 回答

?
DIEA

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超3個(gè)贊

簡(jiǎn)短示例

假設(shè)您正在向https://your-proxy.local. 您的請(qǐng)求處理程序采用該http.Request結(jié)構(gòu)并將其URL字段重寫(xiě)為https://your-apache-backend.local.

您沒(méi)有考慮的是,原始 HTTP 請(qǐng)求還包含一個(gè)Host標(biāo)頭 ( Host: your-proxy.local)。將相同的請(qǐng)求傳遞給 時(shí)http://your-apache-backend.local,該請(qǐng)求中的Host標(biāo)頭仍然顯示Host: your-proxy.local. 這就是 Apache 所抱怨的。

解釋

當(dāng)您使用帶有服務(wù)器名稱指示 (SNI) 的 TLS 時(shí),請(qǐng)求主機(jī)名不僅會(huì)用于 DNS 解析,還會(huì)用于選擇用于建立 TLS 連接的 SSL 證書(shū)。Host另一方面,Apache 使用HTTP 1.1標(biāo)頭來(lái)區(qū)分多個(gè)虛擬主機(jī)。兩個(gè)名稱必須匹配Apache HTTPD wiki 中也提到了這個(gè)問(wèn)題:

SNI/請(qǐng)求主機(jī)名不匹配,或 SNI 提供主機(jī)名而請(qǐng)求不提供。

這是瀏覽器錯(cuò)誤。Apache 會(huì)以 400 類型的錯(cuò)誤拒絕請(qǐng)求。

解決方案

還要重寫(xiě)Host標(biāo)題。如果要保留原始Host標(biāo)頭,可以將其存儲(chǔ)在X-Forwarded-Host標(biāo)頭中(這是一個(gè)非標(biāo)準(zhǔn)標(biāo)頭,但它廣泛用于反向代理):

func (p *Proxy) directorApache(req *http.Request) {

    mainServer := fmt.Sprintf("%s:%d", Config.HostMain, Config.PortMain)

    req.URL.Scheme = "https"

    req.URL.Host = mainServer

    req.Header.Set("X-Forwarded-Host", req.Header().Get("Host"))

    req.Host = mainServer

}


查看完整回答
反對(duì) 回復(fù) 2021-12-07
  • 1 回答
  • 0 關(guān)注
  • 183 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)