2014-01-20 24 views
0

我有一個簡單的go服務器在:8888上偵聽。轉到:相對http.Redirect後面的Apache mod_proxy

package main 

import (
    "log" 
    "net/http" 
) 

func main() { 

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 
    log.Println("redirecting to foo") 
    http.Redirect(w, r, "foo", http.StatusFound) 
    }) 

    http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) { 
    w.Write([]byte("fooooo")) 
    }) 

    if err := http.ListenAndServe(":8888", nil); err != nil { 
    log.Fatal(err) 
    } 
} 

我這個坐在後面的Apache其代理的圍棋服務器的所有請求/bar/*。 我使用ProxyPassMatch來做到這一點。

ProxyPassMatch ^/bar/?(:?(.*))?$ http://localhost:8888/$2 

問題是,就是當我去/bar/我重定向到/foo而不是/bar/foo

有沒有辦法得到這個工作或做我需要/bar前綴我的所有重定向?

回答

1

如果您希望Apache在重定向響應中重寫位置,則還需要在配置中包含ProxyPassReverse指令。這樣的事情應該這樣做:

ProxyPassReverse /bar/ http://localhost:8888/ 
+0

我在'ProxyPassMatch'之後添加了'ProxyPassReverse'指令,它沒有什麼區別。我檢查了日誌,但找不到任何有用的東西。建議? –

相關問題