Monday, May 4, 2009

Run IIS, ASP.net and Apache Together Without Multiple IP Addresses

Many people want to run both IIS and Apache Web Server together. We have already blogged on similar lines: how to add or assign multiple IP addresses to your computers and how to configure their hosts files to loopback virtual hosts to development servers and how to run IIS and Apache together when your computer has multiple IP addresses. Additionally, we have written about configuring Apache to handle different hostnames.

This post will help you run IIS and Apache Web Server together even if you can't manage to add multiple IP addresses (may be because your ISP refuses to assign you so).

It is fairly simple to use Apache Web Server as a proxy to reach IIS. Your sites users will make direct requests to Apache Web Server and when we have finally configured our Apache Web Server, all requests will be proxyed to IIS. You can also configure multiple domains (blogged earlier) in to only proxy requests for particular virtual hosts (particular websites).

Here is what you need to do:

  1. Configure your IIS website to listen to port number 8080 or any other number not in use in your system. So if your website URL was http://www.my-site.com, it will now be http://www.my-site.com:8080/
  2. Start Apache Web Server and make sure Apache can listen to port 80. If Apache web server FAILS, you can use bind settings specified in the earlier post that includes info on changing bind settings of IIS. You may have to restart your server.
  3. Make sure you can start both web server and hit both IIS and Apache from local machine using different ports.
  4. Now open Apache configuration file, httpd.conf. This file is located inside the installation directory under /conf folder. Usually it is placed under: C:\Program Files\Apache Software Foundation\Apache2.2\conf
  5. Scroll to the bottom of this file and add the following text to tell Apache Web Server to load the two following modules and enable proxy sites capability:
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    
    ProxyRequests Off #keep proxy to OFF or your server will act as a forward proxy
    
    
  6. At the bottom, add a new virtual host in the following way: (read howto if you are not sure about vhosts)
    NameVirtualHost *:80
    
    <VirtualHost *:80>
    ServerName www.my-site.com
    ServerAlias *.my-site.com
    DefaultType text/html
    <Directory "C:\Inetpub\wwwroot">
    Options Indexes FollowSymLinks
    AllowOverride none
    Order allow,deny
    Allow from all
    </Directory>
    # sends all requests made to port 80 to another port 8080
    ProxyPass / http://www.my-site.com:8080/
    #makes proper changes to server-side redirection header
    ProxyPassReverse / http://www.my-site.com:8080/ 
    </VirtualHost>
    
  7. Restart Apache Web Server and bingo, you're done!

Now if you access www.my-site.com your requests will be proxied to IIS by Apache Web Server and the only Web server users will be in direct access of will be Apache. Apache and IIS connection will be hidden from your end-users.

ProxyPass is the magic statement and the power of mod_proxy_http and mod_proxy means that you can run any other Application Server or Web Server behind your Apache Web Server and enjoy the benefits of multiple web servers.


This effectively means that you can now run ASP.net with Apache Web Server!
Note: Don't use this technique to create fake Yahoo or GMail sites inside a office network!

☛ Quick Links

♥ Recommended For You