一、配置好Tomcat下虛擬主機即修改tomcatHome/conf/server.xml文件web
具體修改Engine標籤下的host標籤,一對host標籤就對應一個虛擬主機apache
<Host name="www.test1.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t " ;%r" %s%b" /> <Context path="" docBase="caiwu" reloadable="true" crossContext="true"/> </Host> <Host name="www.test2.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context path="" docBase="wkwifi" reloadable="true" crossContext="true"/> </Host>
二、配置用於轉發的Apache的配置文件即修改ApacheHome/conf/httpd.conf文件tomcat
在文件末尾處添加以下用於轉發的配置:app
先打開如下行註釋內容(去掉前面的#): webapp
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
NameVirtualHost *:80 ProxyPreserveHost On <VirtualHost*:80> ServerName www.test1.com ProxyPass / http://www.test1.com:8080/ ProxyPassReverse / http://www.test1.com:8080/ </VirtualHost> <VirtualHost*:80> ServerName www.test2.com ProxyPass / http://www.test2.com:8080/ ProxyPassReverse / http://www.test2.com:8080/ </VirtualHost>
以上兩對VirtualHost標籤分別配置了兩個代理規則將www.test1.com這個域名代理到http://www.test1.com:8080/對應的項目,這樣便可以實現非80端口的tomcat項目經過域名能夠直接訪問的目的。spa