I can’t believe that this is not a solved problem by now, but my Google-fu is failing me. I’m looking for a decent, working extension for Chrome that can redirect a list of hosts to a different server while setting the Host: header to the right address. Everything I’ve found so far assumes that you’re running the servers on different urls. I’m using the same URL on different servers and don’t want to mess around with /etc/hosts.
Please tell me something exists to do this?
on said:
Hmm, my google-fu is strong today:
This one makes the point that what you really need is
a local proxy server configured to do your bidding:
http://superuser.com/questions/343158/simulate-manipulation-of-the-etc-hosts-file-in-google-chrome
But still one answer links to:
https://chrome.google.com/webstore/detail/dns-overrider/acmhaiiijfheggcaanjlgpampclpbnoh/
on said:
I’m currently considering setting up a solution involving using Apache on localhost as a forward proxy to itself. Then I can use a proxy switcher to do what I want. This approach seems to agree with your answer.
That extension only appears to modify the DOM to change links to point to the new server. The HTML will still come from the original server. I did find an extension that allowed you to modify your /etc/hosts in the browser, but you had to make the file world writeable. Unbelievable.
I suspect the reason why this isn’t possible in an extension is before it would be a bad idea to allow extensions to modify DNS responses.
Thanks for your help though.
on said:
The problem generally is that you need to either override the dns lookup with the /etc/hosts, or to somehow trick the browser into thinking it lookied it up by seeding the cache. Nothing I searched for indicates that javascript/chrome extensions could modify the DNS cache of the browser (where youd just “cache” the ip you want and the browser would use that one) which makes sense as there are obvious malicious uses for that. Other than that, the standard way of balancing the same site on more than one server is some proxy like you are already doing. Of course if its development vs production server I don’t see a downside to a subdomain.
on said:
The main reason for wanting to avoid changing the domain name between development and live is that the database contains references to the domains being served. As I plan on doing regular refreshes of development from live, updating these references could be a pain. I think I’ve found a working solution of using a proxy switcher (in this case SwitchySharp) to use the development webserver as a proxy server when I want to use the dev instance. This pretty much just works, although it wouldn’t surprise me if there were subtle corner cases I haven’t considered.
on said:
I usually use iptables DNAT rules to redirect the output to the desired IP address. That takes effect quickly and easily (no reloading proxies) and is transparent to the client.
One thing I haven’t tested (but which should work) is to use iptables rules based on UID so that I can have two browsers running as different users that see different versions of the web site.