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:
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!
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:
- 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/
- 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.
- Make sure you can start both web server and hit both IIS and Apache from local machine using different ports.
- 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
- 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
- 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>
- Restart Apache Web Server and bingo, you're done!
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!
Well that is a good start for me thanks! What if you are running a vmware server with linux on top of windows and you need to forward your request to windows and "Directory "C:\Inetpub\wwwroot" is not accessible directly as windows is on a different internal ip (bridge) not NAT? Thanks.
ReplyDeleteHello, if you are running VMWare, you can use the shared folder feature.
ReplyDeleteVMWare on Windows will allow you to designate a folder to be shared with your Linux image.
Have Fun!
I have followed the steps as mentioned above in my Windows XP machine and I'm able to access the IIS Sites like this http://localhost:8080/mysitename/ but while trying to access the other sites which I have a host entry in Apache are getting a message like "We could not find your www.testsite.com". Can you please tell me what went wrong?
ReplyDeleteFrancis, you need to add host entries on windows 'host' file as well. The 'hosts' file is located in windows/system32/drivers/etc folder.
ReplyDeleteYou will need admin rights to edit the file. You can copy the file, then edit it and then paste it back.
After adding the host entry I'm able get the site accessible. My IIS has default site which is accessible at localhost itself like this http://localhost:8080/ in windows XP. On hitting that it will loads up the site content. But now I’m getting another issue or it might be another question.
ReplyDeleteI have created a host entry “www.mytestapp.loc” for a new test site and I set the document root as “DocumentRoot "D: /Projects/mytestapp" in the virtual host. Now when I hit the “www.mytestapp.loc” its re-routing to the content of IIS site “http://localhost:8080/” but all I want to load is the content of "D: /Projects/mytestapp" location. Is that possible to do this?
Host Entry: 127.0.0.1 www.mytestapp.loc
Apache Virtual host Entry:
ServerName www.mytestapp.loc
ServerAlias *.mytestapp.loc
DocumentRoot "D:/Projects/mytestapp"
Options Indexes FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
#sends all requests made to port 80 to another port 8080
ProxyPass / http://www.mytestapp.loc:8080/
#makes proper changes to server-side redirection header
ProxyPassReverse / http://www.mytestapp.loc:8080/
<VirtualHost *:80>
ReplyDeleteServerName www.my-site.com
ServerAlias *.my-site.com
DefaultType text/html
DocumentRoot "D:/Projects/mytestapp"
<Directory "C:\Inetpub\wwwroot">
Options Indexes FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
Here is the full host entry.
Apache Virtual host Entry:
</Directory>
#sends all requests made to port 80 to another port 8080
ProxyPass / http://www.mytestapp.loc:8080/
#makes proper changes to server-side redirection header
ProxyPassReverse / http://www.mytestapp.loc:8080/
</VirtualHost>
Francis,
ReplyDeleteYour IIS is still listening to port 80.
You need to run one of the following command lines for your OS version:
For Win XP use:
httpcfg.exe set iplisten -i 0.0.0.0:8000
For Vista and Windows server 2008 or later:
netsh http add iplisten ipaddress=0.0.0.0:8000
Read the article in detail here:
http://www.codecurry.com/2009/02/installing-and-running-iis-and-apache.html
So, I think I have my IIS only listening to requests on port 8080 and Apache is set to listen to port 80. I've confirmed this is working by typing in the IP of the pc and appending the port: 192.168.1.3:8080 resolves to the IIS default site, while 192.168.1.3 resolves to the only other site set up under Apache. So, it appears the ports are set correctly. Here's what my httpd.conf file looks like:
ReplyDelete#Add proxy redirect to IIS for iissite.com
ServerName iissite.com
ServerAlias *.iissite.com
DefaultType text/html
Options Indexes FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
# sends all requests made to port 80 to another port 8080
ProxyPass / http://www.iissite.com:8080/
#makes proper changes to server-side redirection header
ProxyPassReverse / http://www.iissite.com:8080/
#Add matttyree.com as virtual host
ServerName apachesite.com
ServerAlias *.apachesite.com
DocumentRoot "C:/xampp/htdocs/apachesite.com/"
The apache site works perfectly. But when I request the iis site, I get a "Service Temporarily Unavailable" error from apache.
What am I missing?
Thanks,
Matt
@Matt
ReplyDeleteSince both Apache and IIS are running on the same server, you should use:
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
# Let me know if that works.
-Sameer
I got it to work once passing it to 192.168.1.103:8080....which is basically what you're suggesting. But, it only loaded the default IIS site. Not the site I wanted. How would I point it to a particular site when using host headers in IIS. In other words, all the sites use the same IP and port, so how do I tell Apache to send the discerning info to IIS?
ReplyDeleteThanks!!!
@Matt
ReplyDeleteYou can have IIS listen to single IP and multiple port numbers. I have detailed it here: http://www.codecurry.com/2009/02/installing-and-running-iis-and-apache.html
In nutshell, use (depending on your version of Wndows):
netsh
http
add iplisten 0.0.0.0:8080
add iplisten 0.0.0.0:8081
OR
httpcfg set iplisten -i 0.0.0.0:8080
httpcfg set iplisten -i 0.0.0.0:8081
----
You will also have to add multiple VHost entries in Apache - that is implicit since you have multiple domains.
Hi Sameer, I did everything you suggested, domain1 is using IIS + PHP 4 + port 8080, domain2 using Apache + PHP5 + port 80. Domain 2 works fine, but whatever I do, domain1 always points to domain2's default doc root. The httpd.conf setting is:
ReplyDeleteProxyRequests Off
NameVirtualHost *:80
ServerName domain1
ServerAlias *.domain1
DefaultType text/html
Options Indexes FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
#ProxyPreserveHost On
# sends all requests made to port 80 to another port 8080
ProxyPass / http://localhost:8080/
#makes proper changes to server-side redirection header
ProxyPassReverse / http://localhost:8080/
Also in the windows\system32\drivers\etc\hosts, I added:
87.xxx.xxx.xxx www.domain1
Could you please kindly tell me what I did wrong? Thank you!
Regards,
Eddie
Can you try to uncomment, ProxyPreserveHost - that can pass required host-header to IIS and then IIS can serve multiple sites.
ReplyDeleteHi, thanks very much for getting back. After uncommenting the line, domain1 still pointing to domain2. I also moved this line outside the '<'VirtualHost'>' group.
ReplyDeleteAny suggestions please?
Do apologize. I wrote the wrong '<'VirtualHost *:80'>' tag, I used a dot instead of colon.
ReplyDeleteNow after I restart Apache, all the sites goes to Domain1. Even Domain2 is pointing to Domain1's default page.
Please help! Thank you very much!
Explains redirection techniques, thanks. However, it mentions about Apache HTTP redirecting requests to IIS. Is it possible to make IIS redirect certain requests to Apache HTTP? My core application architecture is dependent on IIS, but for certain requests, redirecting it to Apache HTTP will help to reduce some load.
ReplyDelete2 years old but still works.
ReplyDeleteI've got Apache answering localhost as expected
and IIS answering localhost:8888 as expected
Before I installed Apache I was running IIS with Simple DNS Plus
where pc.com would load my PC.html which is my personal web page
and where m.com would load my mobile.html which is my mobile version of my personal web page.
Regrettably, this no longer works with Simple DNS Plus.
Does anyone know of a way to get m.com to redirect(?) to localhost:8888/mobile.html
and pc.com to redirect(?) to localhost:8888/pc.html?
tia
Barry G. Sumpter
Hey Barry,
ReplyDeleteYou should checkout my post on running multiple websites using Apache. In your case, you will need to VirtualHost defined in Apache config and both will point to different DocumentRoot.
Reference: http://www.codecurry.com/2009/04/running-multiple-websites-or-domains.html
Thanks!
Sameer
Hey Barry,
ReplyDeleteYou should checkout my post on running multiple websites using Apache. In your case, you will need to VirtualHost defined in Apache config and both will point to different DocumentRoot.
Reference: http://www.codecurry.com/2009/04/running-multiple-websites-or-domains.html
Thanks!
Sameer
Had a fair go but can't seem to get it to work like I want.
ReplyDeleteLeft comment.
Thanks again,
Barry G. Sumpter
ReplyDeleteThe above points are very useful for my research. Please share more like this. Thanks!
LoadRunner Training in Chennai
QTP Training in Chennai
best qtp training institutes in chennai
QTP Training Institutes in Chennai
Best QTP Training Institutes in Chennai
Best QTP Training Center in Chennai
DOT NET Training in Chennai
Html5 Training in Chennai
Thanks for sharing this valuable information to our vision. You have posted a worthy blog keep sharing.
ReplyDeleteSalesforce Training in Chennai
Salesforce Training
Web Development courses in Chennai
ccna course in Chennai
PHP Training in Chennai
gst classes in chennai
ux design course in chennai
Salesforce Training
Salesforce Course in Chennai
Interesting and really attractive blog with some valued content in it. It's hard to see this kind of blog and so thanks for sharing.
ReplyDeleteEnglish Speaking Classes in Mulund
English Speaking Classes in Mulund West
English Speaking Course in Mulund
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
Spoken English Class in Chennai
"Insightful" is the perfect word to describe this wonderful writing of yours. The artistic blend of this subject with your tone of writing made this a great read. Much love 😘.
ReplyDeleteHow to bottom
Such an excellent and interesting blog, do post like this more with more information, This was very useful, Thank you.
ReplyDeleteaviation training in Chennai
cabin crew course in Chennai
diploma in airline and airport management in Chennai
airport ground staff training in Chennai
Aviation Academy in Chennai
air hostess training in Chennai
airport management courses in Chennai
ground staff training in Chennai
This article is a very interesting and brief explanation about this topic. I eagerly waiting for your next post...
ReplyDeleteSpark Training in Chennai
Spark Training Academy
Oracle Training in Chennai
Excel Training in Chennai
Oracle DBA Training in Chennai
Embedded System Course Chennai
Tableau Training in Chennai
Power BI Training in Chennai
Social Media Marketing Courses in Chennai
This article is very interseting
ReplyDeletepython training in chennai
Thanks for sharing valuable information.
ReplyDeleteDigital Marketing training Course in Chennai
digital marketing training institute in Chennai
digital marketing training in Chennai
digital marketing course in Chennai
digital marketing course training in omr
digital marketing certification in omr
digital marketing course training in velachery
digital marketing training center in Chennai
digital marketing courses with placement in Chennai
digital marketing certification in Chennai
digital marketing institute in Chennai
digital marketing certification course in Chennai
digital marketing course training in Chennai
Digital Marketing course in Chennai with placement
digital marketing courses in Chennai
ReplyDeleteThanks of sharing this post…Python is the fastest growing language that helps to get your dream job in a developing area. It says every fundamental in a programming, so if you want to become an expertise in python get some training
Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
It is really a very informative post for all those budding entreprenuers planning to take advantage of post for business expansions. You always share such a wonderful articlewhich helps us to gain knowledge .Thanks for sharing such a wonderful article, It will be deinitely helpful and fruitful article.
ReplyDeleteCyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course | CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course
ReplyDeleteThanks of sharing this post…Python is the fastest growing language that helps to get your dream job in a developing area. It says every fundamental in a programming, so if you want to become an expertise in python get some training
Cyber Security
Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course
in Chennai | Certification | Ethical Hacking Online Training Course | CCNA Training Course in Chennai |
Certification | CCNA Online Training Course | RPA
Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course
Chennai | SEO Training in Chennai |
Certification | SEO Online Training Course
Salesforce users have been complaining majorly about the User Interface being clunky. The web has moved to responsive design and the Salesforce UI did not evolve at the same rate, initially. Salesforce training in Chennai
ReplyDeleteI enjoyed reading your article. Thanks for taking the time to post such a valuable article.
ReplyDeleteseo content writing tips
language similar to english
salesforce basics
star certification
hacking books