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?

link|improve this question
Most people in your situation run a couple of WinXP or Ubuntu virtual machines with different HOSTS configs. – digitxp Dec 13 '10 at 23:14
@digitxp - Yes, I'd already thought of that but i really don't want the overhead of multiple VM's and several entire OS's just to browse a couple of sites. Obviously, if there is no other choice that's what i'll probably have to do.. – Mystere Man Dec 13 '10 at 23:18
If all else fails: Fiddler Web Debugger (Windows) or GlimmerBlocker and Charles Web Debugging Proxy (Mac) can rewrite the requests on the fly... – Arjan Dec 13 '10 at 23:30
@Arjan - Proxies will work to some extent, but I would have to have a seperate proxy instance for each browser instance, or change proxy settings each time which is even more annoying that changing host files. – Mystere Man Dec 13 '10 at 23:45
1  
Perhaps a Web Proxy like squid, would let you redirect in a way that does what you want done from DNS resolution? (of course a web proxy can be configured on a per browser basis) – barlop Dec 15 '10 at 11:15
show 3 more comments
feedback

4 Answers

Privoxy can be used for this purpose.

link|improve this answer
How, exactly, would Privoxy work for this purpose? It looks like just another local proxy server, none of which work because with most browsers you can't define a proxy per instance.. you can only define the global proxy for all instances – Mystere Man Feb 4 '11 at 5:48
@MystereMan: It would proxy your requests and thus manipulate the requests into other requests, it's fairly easy to do that. You are talking non-sense about the proxy servers: Mirosoft Internet Explorer (GUI), Mozilla Firefox (GUI), Google Chrome (CLI --proxy-server=), Apple Safari (GUI), Opera (GUI) and any other browser (GUI or CLI) allows you to set your own proxy server... – Tom Wijsman Feb 4 '11 at 14:05
@TomWij - No. IE, Chrome, and Safari all use the global proxy server setting in "Internet Settings". That means, if you change it in one web browser, it changes in all of them. Firefox has its own settings for this, but unfortunately I can't use Firefox because it doesn't work with the CMS we use (everything else does). – Mystere Man Feb 4 '11 at 15:44
@Mystere Man: Incorrect. Stop repeating your thoughts and instead see what configuration each individual browser gives you. If you aren't spending the effort to actually read documentation then you will never get to solve your problem as you are asking something too specific that doesn't apply to the rest of the people. As I said before but you didn't seem to have read: Any browser allows you to set the proxy server for that browser. Google Chrome provides the CLI parameter --proxy-server=. – Tom Wijsman Feb 4 '11 at 15:46
1  
Hmm, I might be wrong about Safari as I didn't use that for quite some time. But I think I misunderstood you, why would you want to have a different proxy server in every single browser? I'm getting confused as why something like "x.com = production; stage.x.com = staging; dev.x.com = development" wouldn't just work for you given a single IP and host header redirection on the server... – Tom Wijsman Feb 4 '11 at 18:16
show 1 more comment
feedback

I know this isn't what you're asking for, but a temporary solution could be to write a batch script to swap the hosts files and then claunch the browser.

At least it would minimize the the work you're doing.

Or you could just name these server something entirely different in the hosts file so you never have to switch it to begin with.

link|improve this answer
I can't rename them because the web applications depend on the host name to render the right content. Also, the reason I wish to do this is that i can run multiple browsers at the same time and have one go to staging and another to dev. You can't do that by swapping hosts files. – Mystere Man Dec 13 '10 at 23:26
@MystereMan: If you are talking about META BASE, just do browser detection server-side. You shouldn't have your own host name in any other URL... – Tom Wijsman Feb 4 '11 at 14:10
@TomWij - No, i'm not talking about META BASE. I'm talking about host based virtual hosting, not IP based. The hostname field determines which site is accessed. – Mystere Man Feb 4 '11 at 15:46
@MystereMan: Then your first comment on this answer doesn't make any sense. As you are talking about "the web application rendering the right content", I don't see what virtual hosts have to do with that? – Tom Wijsman Feb 4 '11 at 15:51
@TomWij - We have a multi-tennant CMS system that hosts multiple sites on a single server, with a single IP. To view any given site, you Must use a hostname, otherwise you only access the default instance. I need to switch between production, staging, and development versions of this server, which means changing the mapping of domain names to their IP addresses on the fly. I can do this in the hosts file, but that changes things globally so i can't open simultaneous copies of staging and production in two different browser instances. – Mystere Man Feb 4 '11 at 16:20
show 4 more comments
feedback

i'm not quite sure if that's what you want, but did you consider for example using something like firefox profiles + switchhosts?

link|improve this answer
Sadly, profiles do not allow you to store your own hosts file as far as i can tell. Also, switchhosts switches the main hosts file, this will affect other instances of the browser which is what i'm trying to avoid. I want to be able to run two instances, side by side, one going to staging, one to dev. – Mystere Man Dec 13 '10 at 23:23
feedback

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=/etc/hosts-squid

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.