Browser with its own hosts file

browserhosts-fileportable

I have a number of staging and test servers that I need to constantly modify my hosts file to access (they depend on the domain name, so I have to change the hosts file to get them to work).

I find this annoying. I'd like to setup a portable browser of some kind for each kind of site I want to work with. Is there any version of any graphical web browser (including browsers based on the rendering engines of other browsers) that will do this?

This way I can simply launch the instance that's already configured to work with staging if I want to test staging.

Any ideas?

EDIT: The important feature is the ability to run two browsers concurently, both browsing to some-address.com, but with one browser directing the reqests to the server at 1.2.3.4 and the other browser directing the requests to the server at 5.6.7.8.

EDIT: (3/16/14)

This question was asked several years ago, and I still don't know of a decent way to do this. Let me try to explain further, because people seem to misunderstand the problem. It's not something that can be easily fixed just by using a proxy server. I suppose it might be possible to write extensive rules in a proxy server to solve the problems, but that's a huge complex solution to what should be a simple problem.

So to clarify:

There are three web servers. Production, Test, and Development. Each runs a multi-tenant application that customizes itself based on the hostname used to access it. Conceptually, this is similar to a Content Management System or blog engine that allows multiple sites to be run off the same server instance. You just point the hostname to the server, and whichever hostname is used to access it via HTTP 1.1 hostname mapping, is the site it displays.

Any solution which simply rewrites the host file doesn't work because of the requirement to run multiple browser windows at the same time to the different sites, production, development, test, etc… So simply constantly altering the host file doesn't work because it affects all browser instances. If you change the mapping for one browser, then the other browsers are also now mapped to that server so any subsequent requests will go to the wrong server.

All i'm looking for is a way to force this browser instance to use this host file, and that browser instance to use that host file, such as through a command line parameter. I don't even care if I need to install multiple copies of the browser.

This may be doable with firefox portable, since I think it uses its own config files per installed copy, but the problem is that the third party software used to administer the sites does not work with firefox (the sites themselves do, but the admin tools do not, they work fine with chrome and IE and Opera, however.. and I have no access to the source for this to fix it).

Best Answer

Squid solved the problem for me. I think many proxy servers could do the same.

Specifically, I had to install Squid. Then change the squid.conf so that it accessed an alternate hosts file. This is the line you want to change:

#hosts_file /etc/hosts

In my case I used hosts_file /etc/hosts-squid. I created the /etc/hosts-squid file and changed the hosts-squid file so that it would give me access to the new IP addresses that I wanted for the given URL. That was all I needed to do to configure the Squid proxy server.

I then created a command to launch my browser with the proxy settings. I used:

chromium-browser --proxy-server=localhost:3128

Running that command effectively give me a running instance of chromium which can access the domains setup in the hosts-squid file that I created.

I was also able to setup more proxy servers using multiple instances of Squid to access a production, development and local website all on the same computer. Instructions on how to run multiple Squid instances is here. I also wrote a blog post explaining the problem and solution in a little bit more detail.

Related Question