簡體   English   中英

轉到:Apache mod_proxy后面的相對http.Redirect

[英]Go: relative http.Redirect behind Apache mod_proxy

我有一個簡單的go服務器,監聽:8888

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/*所有請求代理到go服務器。 我正在使用ProxyPassMatch來做到這一點。

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

問題是當我轉到/bar/我被重定向到/foo而不是/bar/foo

有沒有一種方法可以使此工作正常進行,或者是否需要在所有重定向之前添加/bar前綴?

如果希望Apache在重定向響應中重寫位置,則還需要在配置中包括ProxyPassReverse指令。 這樣的事情應該可以解決問題:

ProxyPassReverse /bar/ http://localhost:8888/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM