diff --git a/README.md b/README.md index d2497b6..78940c3 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,33 @@ server { } ``` +The parameter 'http-proxy-redir-url' in rttys.conf can also be configured +by setting a new HTTP header 'HttpProxyRedir' in nginx. + +``` +server { + listen 80; + + server_name rtty.your-server.com; + + location /connect/ { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_pass http://127.0.0.1:5913; + } + + location /web/ { + proxy_set_header HttpProxyRedir http://$server_name; + proxy_pass http://127.0.0.1:5913; + } + + location / { + proxy_pass http://127.0.0.1:5913; + } +} +``` + ## Docker ### Simple run diff --git a/README_ZH.md b/README_ZH.md index 73f516a..11c1197 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -130,6 +130,46 @@ server { } ``` +在 rttys.conf 中的参数 http-proxy-redir-url 也可以通过在 nginx 中设置一个新 +的 HTTP header HttpProxyRedir 来配置. + +``` +server { + listen 80; + + server_name rtty.your-server.com; + + location /connect/ { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_pass http://127.0.0.1:5913; + } + + location /web/ { + proxy_set_header HttpProxyRedir http://$server_name; + proxy_pass http://127.0.0.1:5913; + } + + location / { + proxy_pass http://127.0.0.1:5913; + } +} + +server { + listen 80; + + server_name web.your-server.com; + + location / { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_pass http://127.0.0.1:5914; + } +} +``` + ## Docker sudo docker run -it -p 5912:5912 -p 5913:5913 -p 5914:5914 zhaojh329/rttys:latest \ diff --git a/http.go b/http.go index 743e1cc..bf1c39d 100644 --- a/http.go +++ b/http.go @@ -307,7 +307,10 @@ func httpProxyRedirect(br *broker, c *gin.Context) { return } - location := cfg.HttpProxyRedirURL + location := c.Request.Header.Get("HttpProxyRedir") + if location == "" { + location = cfg.HttpProxyRedirURL + } if location == "" { host, _, err := net.SplitHostPort(c.Request.Host)