[GH-ISSUE #84] On reload redirects to the local address #43

Open
opened 2026-05-05 10:58:29 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @applegrew on GitHub (Jul 29, 2018).
Original GitHub issue: https://github.com/mmatczuk/go-http-tunnel/issues/84

I am facing a weird issue. My tunnel.yaml file is as below :-

server_addr: example.com:5223
tunnels:
      now:
        proto: http
        addr: http://127.0.0.1:8080
        host: me.example.com

On server side -httpAddr is set to :8000. When I access the site from the browsers as http://me.example.com:8000 it works fine. However, when I reload the site I get a 302 from the site and I am redirected to http://127.0.0.1:8080. The actual site does not seem to issue the 302. It seems like go-http-tunnel is issuing that for some reason. If I goto some other url and come back to the same url I do not get the 302; it is only when I hit the same url twice consecutively I get the 302. If I change the addr: to say https://google.com then I do not see this issue.

Originally created by @applegrew on GitHub (Jul 29, 2018). Original GitHub issue: https://github.com/mmatczuk/go-http-tunnel/issues/84 I am facing a weird issue. My tunnel.yaml file is as below :- ``` server_addr: example.com:5223 tunnels: now: proto: http addr: http://127.0.0.1:8080 host: me.example.com ``` On server side `-httpAddr` is set to `:8000`. When I access the site from the browsers as `http://me.example.com:8000` it works fine. However, when I reload the site I get a 302 from the site and I am redirected to `http://127.0.0.1:8080`. The actual site does not seem to issue the 302. It seems like go-http-tunnel is issuing that for some reason. If I goto some other url and come back to the same url I do not get the 302; it is only when I hit the same url twice consecutively I get the 302. If I change the `addr:` to say `https://google.com` then I do not see this issue.
Author
Owner

@Harvey-Kaer commented on GitHub (Apr 23, 2019):

Hi applegrew,
I am facing a similar issue as redirected to localdomain of the client.
Do you manage to find a solution?

<!-- gh-comment-id:485891154 --> @Harvey-Kaer commented on GitHub (Apr 23, 2019): Hi applegrew, I am facing a similar issue as redirected to localdomain of the client. Do you manage to find a solution?
Author
Owner

@applegrew commented on GitHub (Apr 23, 2019):

Nopes.

On Tue, 23 Apr, 2019, 10:36 PM Harvey-Kaer, notifications@github.com
wrote:

Hi applegrew,
I am facing a similar issue as redirected to localdomain of the client.
Do you manage to find a solution?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/mmatczuk/go-http-tunnel/issues/84#issuecomment-485891154,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADKDDRR6V5DCMUQGOW4ZMDPR46YZANCNFSM4FMVRTSA
.

<!-- gh-comment-id:485966068 --> @applegrew commented on GitHub (Apr 23, 2019): Nopes. On Tue, 23 Apr, 2019, 10:36 PM Harvey-Kaer, <notifications@github.com> wrote: > Hi applegrew, > I am facing a similar issue as redirected to localdomain of the client. > Do you manage to find a solution? > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > <https://github.com/mmatczuk/go-http-tunnel/issues/84#issuecomment-485891154>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/AADKDDRR6V5DCMUQGOW4ZMDPR46YZANCNFSM4FMVRTSA> > . >
Author
Owner

@Harvey-Kaer commented on GitHub (Apr 25, 2019):

After some search and trial, I found a solution works for me. I use nginx as proxy for go-http-tunnel and rewrite the HTTP header using proxy_redirect.

`

server {

# HTTPS is used
listen 443;
server_name *.kaertest.harveyliu.me;

ssl on;
ssl_certificate			/path/to/cert;
ssl_certificate_key		/path/to/private_key;

location / {
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Real-IP $remote_addr;

	#replace [tunneld_httpsAddr] with a new port for your tunneld
	proxy_set_header Host $host:[tunneld_httpsAddr];
	proxy_pass https://127.0.0.1:[tunneld_httpsAddr];

	#proxy_redirect will rewrite the local hostname in the header
	proxy_redirect ~^http://[^/]+(/.*)$ https://$http_host$1;
}

}

`

Then run tunneld on your server with additional -httpsAddr flag (or -httpAddr if you only need HTTP):
tunneld -httpsAddr [tunneld_httpsAddr] -tlsCrt /path/to/cert -tlsKey /path/to/private_key

===============================================================
References:
As of hint of OP, I looked into the packages around 302 Redirect and found the "LOCATION" header was responded as "localhost" or local domain in some packages.

https://stackoverflow.com/questions/46947548/ngrok-not-passing-my-post-request-on-to-localhost
ngrok has a -host-header=rewrite flag so I'm looking for a similar one.

Then I decided to use nginx to redirect package:
https://serverfault.com/questions/428793/using-nginxs-proxy-redirect-when-the-response-locations-domain-varies
(for the regex in proxy_redirect, I used ~^http://[^/]+(/.*)$ instead of ~^http://[^/]+(/.+)$ so that empty path string (like http://localhost/) will also be redirected.

<!-- gh-comment-id:486490719 --> @Harvey-Kaer commented on GitHub (Apr 25, 2019): After some search and trial, I found a solution works for me. I use nginx as proxy for go-http-tunnel and rewrite the HTTP header using `proxy_redirect`. ` server { # HTTPS is used listen 443; server_name *.kaertest.harveyliu.me; ssl on; ssl_certificate /path/to/cert; ssl_certificate_key /path/to/private_key; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; #replace [tunneld_httpsAddr] with a new port for your tunneld proxy_set_header Host $host:[tunneld_httpsAddr]; proxy_pass https://127.0.0.1:[tunneld_httpsAddr]; #proxy_redirect will rewrite the local hostname in the header proxy_redirect ~^http://[^/]+(/.*)$ https://$http_host$1; } } ` Then run tunneld on your server with additional -httpsAddr flag (or -httpAddr if you only need HTTP): `tunneld -httpsAddr [tunneld_httpsAddr] -tlsCrt /path/to/cert -tlsKey /path/to/private_key` =============================================================== References: As of hint of OP, I looked into the packages around 302 Redirect and found the "LOCATION" header was responded as "localhost" or local domain in some packages. https://stackoverflow.com/questions/46947548/ngrok-not-passing-my-post-request-on-to-localhost ngrok has a `-host-header=rewrite` flag so I'm looking for a similar one. Then I decided to use nginx to redirect package: https://serverfault.com/questions/428793/using-nginxs-proxy-redirect-when-the-response-locations-domain-varies (for the regex in `proxy_redirect`, I used `~^http://[^/]+(/.*)$` instead of `~^http://[^/]+(/.+)$` so that empty path string (like `http://localhost/`) will also be redirected.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/go-http-tunnel#43
No description provided.