Solution for sharing port 80 between APACHE and IIS

Source: Internet
Author: User
Tags website server

Recently, our Organization was commissioned by our brother organizations to help them develop a website. The website was developed using PHP Technology and released through Apache. After the website development is complete, you may encounter unexpected problems when preparing to deploy the website to the server. Apache and the server's existing IIS have port 80, websites published through Apache cannot be accessed. By looking for relevant information, we finally solved the problem of port 80 conflict between APACHE and IIS. Next I will briefly introduce how we solve this problem.

I. server environment

The server on which I publish my website is Windows Enterprise Edition. I have installed IIS service software on it to publish websites using ASP and Asp.net technologies. The server has only one Nic, so there is only one external IP. Later, Apache was installed on the server because of the PHP Technology Development website.

Ii. cause of the problem

Anyone who has experience developing a website knows that a netizen accesses a website through the HTTP protocol, while the default port of the HTTP protocol to access the server is 80, therefore, most website publishing software supports the default port 80. If only one type of website publishing software is installed on one server, All accesses are normal. However, when two or more types of website publishing software are installed, port 80 conflict occurs. This is because when a request requests to access a website on the server, it also requests port 80 of the server. A problem occurs here, the server does not know the website to which the request is sent to publish software, at this time, the server will only check which website is released in the default order, which occupies port 80 first, and then go to the published software to find the desired website. If the request is found, an error message is returned to the user. If the request is not found, an error message is returned to the user.

Iii. Problem Solving Process

After knowing the reason, we finally found a solution through our efforts and constant attempts.

At first, someone suggested whether to change the default port of the Software published on one of the websites (that is, to change the default port 80 to another port ), when this is proposed, it is immediately rejected, because once the default port of software is changed for a website (for example, port 80 is changed to port 81 ), when a netizen accesses the website, it is necessary to enter a port number (for example: http://www.a.com: 81) in the back of the website, it is inconvenient, and it is not convenient for the promotion and memory of the website. Why do the modified port numbers have to be entered after the URL? This is because our website is accessed through the HTTP protocol, and the HTTP protocol, as we mentioned earlier in the article, is used by default to access port 80 of the server, you cannot identify the modified port number by yourself. Therefore, you must add the modified port number for the modified port number so that the HTTP protocol can access the modified port.

After the first solution was denied, after discussion, the second solution was created again, that is, adding a NIC to the server so that the server has two NICs, then bind two different Internet IP addresses to the two NICs, and then point IIS and Apache to one IP address respectively, so that IIS and Apache will not generate port 80 conflict. After this scheme is proposed, everyone agrees that it is feasible. The reason for believing it is feasible is also based on the HTTP protocol access principle. Generally, the website server has only one IP address. Although the Internet users access the website through the domain name, the website still accesses the IP address of the server through the domain name resolution service, by default, the HTTP protocol under an IP address can only access the default port 80 under this IP address. If a server has two IP addresses, the default port 80 under the two IP addresses does not conflict. Although this solution is feasible, we soon discovered that all the public IP addresses of the Organization are used up, and there are no redundant public IP addresses. It's really bad luck! This solution is aborted.

After the death of the second Plan, everyone fell into a painful meditation and searching. After a day of retreat, we finally found the third solution. In addition, this solution has been unanimously recognized by everyone in terms of feasibility, operability, efficiency, and cost saving. What is a good solution that can be unanimously recognized by everyone? Simply put, this solution enables IIS to publish the website on IIS through the Apache proxy mechanism, while the website on Apache is released through Apache itself. This may be the case, but you still don't quite understand it. I will tell you the specific steps below.

Let's assume an experiment environment. The experiment environment is like this: Use Apache to proxy IIS to achieve integration of virtual Apache and IIS. Suppose there are three websites, website a, website B, and website C, where website a and website B are deployed on IIS, and website C is deployed on Apache. That is, when a user requests a.com and B .com, Apache will explain them in a unified manner, and Apache will automatically redirect virualhost to IIS. Apache will explain and publish the requests for c.com.

Step 1: Change the default port of the website published by IIS from 80 to 8080;

Step 2: Modify the httpd. conf configuration file of Apache.

To enable Apache to support forwarding, that is, to act as an IIS proxy, you must first enable the Apache proxy module. first, find httpd under the apache \ conf directory. CONF file. open the file in notepad and find the following lines of code:

# Loadmodule proxy_module modules/mod_proxy.so

# Loadmodule proxy_connect_module modules/mod_proxy_connect.so

# Loadmodule proxy_ftp_module modules/mod_proxy_ftp.so

# Loadmodule proxy_http_module modules/mod_proxy_http.so

Remove the "#" sign before each line of code, and then open the Apache proxy module.

Then add the following code to the httpd. conf file:

Namevirtualhost 111.111.111.111: 80

 

<Virtualhost *: 80>
DocumentRoot D:/Apache/www/test1 (note: the actual local address of Site C)
Servername www.c.com
</Virtualhost>

<Virtualhost 111.111.111.111: 80>
Servername www.a.com
Proxypass/http://www.a.com: 8080/
Proxypassreverse/http://www.a.com: 8080/
</Virtualhost>

<Virtualhost 111.111.111.111: 80>
Servername www. B .com
Proxypass/http://www. B .com: 8080/
Proxypassreverse/http://www. B .com: 8080/
</Virtualhost>

In the code above, 111.111.111.111 indicates the IP address of the server, and the actual address of the server should be used in actual applications.

Step 3 restart the apache service

This step is essential, otherwise the settings we made in the previous two steps will not take effect.

After completing the preceding three steps, we can access www.a.com, www. B .com, and www.c.com. No website can be accessed. This indicates that the settings are successful, now, the problem of sharing port 80 between APACHE and IIS has been solved. Finally, I hope this article will help those who are suffering from the same problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.