3

While developing websites (using win7) I find myself changing the IP addresses in my hosts file quite often. I have a development environment on my machine, code on the testing server, code on the staging server and code on the live server. I toggle through these servers a bunch of times throughout the day. I normally manage this by having a slew of host entries commented out, uncommenting the one I want to use and then using ipconfig /flushdns and finally restarting my browser. Such a PITA!!

I've read that installing a proxy server locally would take several steps out of this process. What's the best proxy server (on win7) for this scenario?

Michael Gorham
  • 1,136
  • 2
  • 15
  • 24
  • How about if you have you dev in site.dev domain and production on the production url? – Jure C. Nov 14 '12 at 23:51
  • 2
    @JureC. the web site code uses the domain name to determine which style settings to show. Sub domains are out of the question too. – Michael Gorham Nov 15 '12 at 00:49
  • FYI - At the moment, in lieu of a proxy solution, I'm currently using Simple Hosts Editor by Nilesoft to toggle between hosts settings and using Chrome's Host Resolver Cache clearing button (chrome://net-internals/#dns). – Michael Gorham Jan 12 '13 at 17:37

4 Answers4

0

You can set up your host file to point the domain to a LAN ip (just to prevent packets going somewhere in case you break something), then you would need a proxy that dynamically changes the destination. What you're looking for is a Reverse Proxy, such as Squid or Varnish. Unfortunately the set up of such a server is beyond my knowledge.

miniBill
  • 1,773
  • 17
  • 40
  • Close, but I'm looking for an explanation of how to setup such a proxy server from a developer addressing the same problem as described above. – Michael Gorham Dec 16 '12 at 00:07
0

What you could do is create 3 hosts files; hosts_1, hosts_2 and hosts_3, in the hosts directory; C:\Windows\System32\Drivers\Etc, each with resp. the test, staging and live setting. You could then write a batch file (*.bat) which overwrites the real hosts file with the hosts setting of your choice, for instance with a user prompt.

@echo off
set /p UserInputPath= Which hosts file? (1=test, 2=staging, 3=live)
cd C:\Windows\System32\Drivers\Etc
xcopy /y hosts_%UserInputPath% hosts
ipconfig /flushdns

Combine this example with some commands for killing the browser process, restarting it, etc. Googling 'batch + processes' can help you.

0

Copy your normal hosts file into hosts.normal, hosts.testing, hosts.staging and hosts.live. For each file have a bat file, which deletes the current hosts and copies the appropriate hosts.* file into hosts. Then you can just run the chosen batch file to switch configuration.

Additionally, pin command prompt into taskbar. This way you can just right click the icon and you should see the batch files in the context menu. Pin them and you'll have a quick access menu for these configs in your taskbar.

But otherwise I'd just use web.config transforms to handle this kind of situation.

Jani Hyytiäinen
  • 4,804
  • 32
  • 45
0

you can use http://hostprofiles.codeplex.com/ pretty handy.

Greetings Gijs

ShopWorks
  • 71
  • 1
  • 7