

HowTo: Vista: Use NETSH to Run IIS7 & Apache on port 80 - jdavid

Vista: Use NETSH to Run IIS7 &#38; Apache<p>Setting up IIS7 &#38; Apache to use virtual hosting on port 80<p>Introduction<p>Like many of you I was skeptical about Vista for a number of reasons, it had a cloudy feature set, rumors of palladium code, and well, people told me it was slow.  And don’t forget that since it requires new drivers, most of the drivers are just coming out of beta and were quite buggy for some time.<p>However, I am here to tell you that there are some really KICK ASS features in Vista that you have never heard about, and the new NETSH or Network Shell command line tool is one of them.  Linux users have had tools like the new NETSH for a while now, but now Windows has it two.<p>To make use of this little trick we are going to use NETSH HTTP (Network Shell) an upgraded command line utility that comes only with newer versions of Windows like Windows Server 2008 and Windows Vista.  This particular command allows you to manage what ports you listen to for HTTP traffic.<p>By default most webservers listen to your computer’s loopback address 127.0.0.1 (http://en.wikipedia.org/wiki/Loopback) or LOCALHOST for traffic.  The problem is that they also bind to port 80 on LOCALHOST, which blocks other applications or services on your computer from binding to that same port, which is exactly what we are trying to get around. Some default settings for server apps like apache and iis7 bind to all network interfaces (IP addresses) on port 80 making it worse.  To get around this I use a little known fact of network architecture, which is that the loopback address of 127.0.0.1is not the only loopback address that is reserved for your computer.  In fact the entire 127.x.x.x address space is reserved just for your internal machine.<p>I have to admit that I was inspired by this article on the web to overload the network interface with two IP addresses, but where they use the 192.x.x.x IP address space reserved for local internal networks (10.x.x.x is also reserved for the same purpose), so I decided to use the network reserved for your computer’s internal loopback, which results in fewer network effects on your local network where other computers in your office might need to communicate with you.  So in my setup, you will have one external IP to send requests to, and multiple web servers responding to them.<p>The second part of this hack, requires you to use HTTP 1.1 protocols or virtual hosting. (http://en.wikipedia.org/wiki/HTTP#HTTP_1.1_Upgrade_header)  HTTP added a very widely used but forgotten feature that specifies the HOST’s domain name in the http request.  Many servers like IIS and Apache then use the domain name to determine which site to server.  This allowed one machine to host many sites, and subdomains of a network.  So in our network we want http://apache.foo.com and http://iis7.foo.com to host from the same server, so not only can we branch via a single server now, but we can branch between multiple servers by overloading the loopback.<p>{internet} =&#62; {ext IP 192.0.0.x} =&#62; {loopback 127.0.0.1} =&#62; {127.0.0.2:80 = apache, 127.0.0.3:80 =&#62; iis7}<p>Walkthrough (Vista)<p>Using NETSH HTTP to listen to 127.0.0.2 &#38; 127.0.0.3<p>For additional reference on NETSH HTTP
http://technet.microsoft.com/en-us/library/cc725882(WS.10).aspx<p>1.	Open a command prompt<p>2.	Type: netsh {enter}<p>3.	Type: http {enter}<p>4.	Check existing listeners<p>type: show iplisten {enter}<p>a.	It should be blank<p>5.	Add new listener to 127.0.0.2<p>type: add iplisten ipaddress=127.0.0.2<p>a.	You should get ipaddress successfully added<p>6.	Check existing listeners<p>type: show iplisten {enter}<p>a.	It should show 127.0.0.2 in the list<p>7.	Add new listener to 127.0.0.3<p>type: add iplisten ipaddress=127.0.0.3<p>a.	You should get ipaddress successfully added<p>8.	Type: exit<p>9.	Type: netstat –an<p>a.	Check for 127.0.0.2:80 &#38; 127.0.0.3:80 in the list, this will show your bindings<p>b.	If you see 0.0.0.0:80 you might need to reset iis with iisreset, and or configure iis to bind to a specific interface.<p>Configure hosts (file)<p>1.	Navigate to “C:\WINDOWS\system32\drivers\etc”<p>2.	Open “hosts” in your favorite text editor<p>a.	(mine is jEdit, yours might be notepad.exe, or textpad.exe)<p>3.	Add these two lines to the list<p>a.	127.0.0.3 iis7.foo.com<p>b.	127.0.0.2 apache.foo.com<p>4.	Add any other DNS mappings<p>5.	Save the file<p>6.	Open a command line<p>7.	Type: ipconfig /flushdns<p>8.	Type: ping iis7.foo.com<p>a.	Should show 127.0.0.3<p>b.	may fail to ping if your server is not started or configured<p>9.	Type: ping apache.foo.com<p>a.	Should show 127.0.0.2<p>b.	may fail to ping if your server is not started or configured<p>Stop IIS7<p>1.	You will need to stop iis7 before starting apache because of some pre-startup checks.<p>Configure IIS7<p>1.	Select your site<p>2.	On the right hand side click the link “edit bindings”<p>3.	In the dialog, where you see IP Address, and * (all interfaces), you will need to change that to 127.0.0.3<p>4.	Make sure you have no bindings for iis7 set to * (all interfaces),  and port 80.<p>5.	Turn IIS7 on and see if it hits your site.<p>6.	Turn IIS7 off and leave it off, so we can configure apache.<p>Configure Apache Listeners<p>1.	Open httpd.conf in your favorite text editor<p>a.	(mine is jEdit, yours might be notepad.exe, or textpad.exe)<p>2.	Search for any Listen statements in the file.<p>a.	You might see Listen *:80, or Listen 127.0.0.1:80<p>b.	Change this to read Listen 127.0.0.2:80<p>c.	Comment out any other Listen statements with a #<p>3.	Save the file<p>4.	Start Apache<p>a.	I use wamp, so this is easy<p>5.	Open a command line<p>6.	Ping apache.foo.com<p>a.	Should work now<p>7.	Open a web browser and browse apache.foo.com<p>a.	Should work now<p>Configure Dynamic Virtual Hosting Directories in Apache<p>(will add later, not necessary for now)<p>Start IIS7 up<p>1.	Start IIS7 up.<p>2.	Test iis7.foo.com<p>a.	Ping iis7.foo.com<p>b.	Open browser to iis7.foo.com<p>c.	Both should work.
======
thwarted
I don't use Windows, so I'm confused about what is listening on 192.x.x.x:80
and 127.0.0.1:80. If there is some kind of layer 7 reverse proxy (in IIS,
apache, or some other software) listening on the public addresses, why does it
matter which port, or even which localhost 127/8 address, is being listened on
by the backend servers? Just have IIS listen on 8080 and apache on 8081, and
then

    
    
       {internet} => {ext IP 192.0.0.x = reverse proxy} =>
            {127.0.0.1:8081 = apache, 127.0.0.1:8080 => iis7}
    

If you really want to browse those locally, from the server, using the names
iis7.foo.com and apache.foo.com, then I can see using addresses in 127/8 and
adding the entries to the HOSTS file, but this doesn't seem to be that
valuable of a feature.

~~~
jdavid
the problem arose in that i had to use port 80, and that the host file would
not let you redirect a hostname to a hostaddress:port

------
termie
There's a kernel mode HTTP listener in Windows, which has its own cache and
logging .. IIS (more specifically w3wp.exe worker processes) get requests and
respond through named pipes.

