工作中遇到IIS与tomcat需共用80端口(单IP),按网上的帖子试了N遍未果。后咨询高人,用apache做代理实现了。
1. 网站web1配置IIS使用端口81,启动IIS
注意:
记住设置完成后要停止服务后重启,并用浏览器测试用"http://网站服务器局域网IP:81"可以正常访问
2. 网站web2配置Tomcat下面的server.xml配置文件,使用端口8081并重启Tomcat使配置生效,类似于下面:
<Connector port="8081" proxyPort="80"/>
注意:
* 记住设置完成后要停止服务后重启,并用浏览器测试用"http://网站服务器局域网IP:8081"可以正常访问
3. 配置DNS(即域名解析服务已完成)
* 确保网站1的域名会解析成web服务器的公网ip地址
e.g: www.web1.com -> 202.x.x.194
* 确保网站2的域名会解析成你们web服务器的公网ip地址
e.g: www.web2.com -> 202.x.x.194
4. 安装Apache2.x
5. 配置httpd.conf
2.1 找到下面那几行,然后去掉前面的*号
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.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
2.2 找到下面这行,去掉前面的*号
Include conf/extra/httpd-vhosts.conf
6. 配置Apache目录下面的"conf/extra/httpd-vhosts.conf"
--------------------------------------
#
# Use name-based virtual hosting.
#
NameVirtualHost 网站服务器局域网IP:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost 网站服务器局域网IP:80>
ProxyPreserveHost On
ServerAdmin 的域名(比如www.web1.com)
ServerName web1的域名(比如www.web1.com)
ProxyPass / http://网站服务器局域网IP:81/
ProxyPassReverse / http://网站服务器局域网IP:81/
ErrorLog "logs/web1的域名(比如www.web1.com)-error.log"
CustomLog "logs/web1的域名(比如www.web1.com)-access.log" common
</VirtualHost>
<VirtualHost 网站服务器局域网IP:80>
ProxyPreserveHost On
ServerAdmin 的域名(比如www.web2.com)
ServerName web2的域名(比如www.web2.com)
ProxyPass / http://网站服务器局域网IP:8081/
ProxyPassReverse / http://网站服务器局域网IP:8081/
ErrorLog "logs/web2的域名(比如www.web2.com)-error.log"
CustomLog "logs/web2的域名(比如www.web2.com)-access.log" common
</VirtualHost>
下面是某人试验所用的例子:
--------------------------------------
#
# Use name-based virtual hosting.
#
NameVirtualHost 127.0.0.1:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost 127.0.0.1:80>
#ProxyPreserveHost On
ServerAdmin
#DocumentRoot "C:/Inetpub/wwwroot"
ServerName iis.test123.com
ServerAlias iis.test123.com
ProxyPass / http://localhost:81/
ProxyPassReverse / http://localhost:81/
ErrorLog "logs/iis.test123.com-error.log"
CustomLog "logs/iis.com-access.log" common
</VirtualHost>
<VirtualHost 127.0.0.1:80>
#ProxyPreserveHost On
ServerAdmin
#DocumentRoot "D:apache-tomcat-6.0.24webappsexamples"
ServerName tomcat.test123.com
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/
ErrorLog "logs/tomcat.test123.com-error.log"
CustomLog "logs/tomcat.test123.com-access.log" common
</VirtualHost>
7. 启动Apache
IIS与tomcat共用80端口的问题是解决了,3网站用域名访问都OK了。但是web2中jsp页面显示不完整。因为我用tomcat虚拟主机发布了两个网站,可能tomcat的server.xml文件还没配置好吧。未完待续。。