omphalos/subproxy

Redirect

Closed this issue · 10 comments

Hello, as i see it just redirects to the subdomain, and url changes to the subdomains.
So there is no real proxing.

Please suggest, why?

Hello. Thanks for opening an issue. Unfortunately, I am not able to reproduce it. Can you please tell me which operating system you are on and which browser? Also, can you give me an example of which subdomain you are trying -- specifically what url do you enter into your browser?

Not sure if this helps but on Linux with Chrome if I run subproxy on 8081 with the following into my hosts file:

127.0.1.1 google.com.localhost

And I navigate to google.com.localhost:8081, I will get redirected. Everything works fine if I prefix the site with "www." however:

127.0.1.1 www.google.com.localhost

The difference is the www.

The reason for this behavior is that google returns a location header pointing at www.google.com, and it appears Chrome will automatically redirect if the location doesn't match the url. Subproxy will detect a location header if there is one and replace it, but only if it matches what's requested. So in this case, what is happening is that subproxy gets a request for google.com.localhost:8081, sends a request for google.com, but gets a header with www.google.com. Subproxy doesn't replace this header since it doesn't match the subdomain, This header gets sent back to the browser as-is. Then Chrome sees a different location and redirects.

Maybe this is the case you are running into. If you are still having a problem, please provide more detail and I will try to reproduce it.

I am using win 7 and latest chrome.
And tested on www.google.com, followed by example.
Subproxy have installed via npm.

So , should I try to use without www?
I have faced with the same issue on other sites too. May be you could suggest the workaround?

Thanks

Just tried on Windows 7 with a fresh install from npm. Unfortunately I am not able to reproduce this issue. I don't see why trying without www would work for google - to proxy google it seems that www is needed in the url and the hosts file, since that matches their location header. But you can try it. I've also successfully tested example.com.localhost:85 and www.example.com.localhost:85 when I add the respective entries to my hosts file in Windows 7 (and running on port 85).

Just to confirm, you're adding 127.0.0.1 www.google.com.localhost to your hosts file, and navigating to www.google.com.localhost:85 (www included) in Chrome?

Also, are you using any other proxy while using subproxy? I wonder if there could be some troublesome interaction somewhere.

Since I can't reproduce this it's going to be hard for me to resolve the issue you're seeing. One thing you could try is to use fiddler to inspect the http traffic to see what is redirecting you. Or just using the network tab in Chrome dev tools might give you enough info to see what the problem is.

I have added as 127.0.01 www.google.com.localhost to my hosts file.
And navigated as you have described.

I am not using another proxies.

I could provide info you need. Just tell me what to track.

p.s. is there any difference what to use as separator in hosts file: spaces or tabs?

I have four spaces to separate the IP from the hostname in my hosts file on my Win 7 machine. I'm not sure if tabs make any difference.

If you open fiddler, then navigate to some url from Chrome, you will see the url history appear in fiddler. This is because it is intercepting all your http requests.

So I wonder where you are encountering the redirect. If you navigate to www.google.com.localhost you should see your *.localhost url followed by the actual url in the fiddler log. If you see a 300-level code (like 301 or 302 or something), that can indicate a redirect.

Also in fiddler you can inspect response headers that come back from the site you are visiting. I would take a look at the location header to see what fiddler comes back with when you navigate to www.google.com.localhost.

Hopefully there is a clue in either these response codes or the location header as to why you are being redirected.

network

Here is what i have

It looks like it is redirecting you to the ukraine google. Could you try adding www.google.com.ua.localhost to your hosts file as well, then navigating to http://www.google.com.ua.localhost:85/ in your browser?

great! it is working. Thank you :)

So, if i deploy this util to the server, i will be able to add subdomains to my primary domain? And proxy sites, right?

Glad it's working.

When deploying this, you should be able to add a wildcard DNS entry: http://en.wikipedia.org/wiki/Wildcard_DNS_record

Let's say your host is example.com. In that case you should be able to add a DNS entry like *.example.com to direct all example.com traffic to your proxy.

Just be aware that subproxy doesn't intercept redirects. When a server sends a redirect, subproxy just forwards that to your client. So if you try to proxy something like www.google.com from the Ukraine, then the redirect will send clients to www.google.com.ua. That is what is happening in your fiddler log. Subproxy doesn't tamper with redirect messages. However if someone navigates directly to your domain www.google.com.ua.example.com, and the proxied address doesn't redirect (just as in your case www.google.com.ua doesn't redirect), then you should see the proxied page just fine.

It would probably be possible to add redirect handling to subproxy, but in its current incarnation that's not supported.

I have got it, thanks.
I suppose to have redirect handled is really cool feature.

In any case, thank you very much )