-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reverse proxy 中怎样预设原始Host 头。 #572
Comments
版本太旧。 |
版本换到 gost v3.0.0-nightly.20240904, 但没有成功(503 Service Unavailable),若将addr更改回IP就可以。另外我通过 nginx 本地内网IP站 反向代理 https站成功,更换采用gost 则不成功。能否给一下这方面的示例: http -- http , http --- https , 预设原始Host头的 example 示例? |
已经换用新的版本了,请问能否提供一个示例。 |
试试下面配置: services:
- name: http
addr: :80
handler:
type: tcp
metadata:
sniffing: true
listener:
type: tcp
forwarder:
nodes:
- name: example-com
addr: example.com:80
http:
host: www.example.com |
无法成功,
返回 HTTP ERROR 503 但我直接golang 用 "net/http/httputil" 包实现则可以 func main() {
// 解析远程服务器的 URL
target := "https://www.baidu.com"
remote, err := url.Parse(target)
if err != nil {
log.Fatalf("解析目标地址失败: %v", err)
}
// 创建反向代理
proxy := httputil.NewSingleHostReverseProxy(remote)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
r.Host = remote.Host
// 设置代理头信息
r.Header.Set("X-Forwarded-Host", r.Header.Get("Host"))
r.Header.Set("X-Forwarded-For", r.RemoteAddr)
log.Printf("代理请求: %s %s", r.Method, r.URL.String())
proxy.ServeHTTP(w, r)
})
addr := ":8080"
log.Printf("启动代理服务器, 监听 %s", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatalf("代理服务器启动失败: %v", err)
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
eg. nginx reverse proxy 配置
我在以下地方配置 没有成功。
请教一下我应该在哪配置
The text was updated successfully, but these errors were encountered: