|
The origin of the problem
Company LAMP server using Apache's VirtualHost feature to deploy multiple independent domain sites. httpd.conf configuration file are the following:
# Omitted herein independent portion
Listen 80
# Www.xxx.com
< VirtualHost *>
ServerAdmin xxx@126.com
DocumentRoot "/ var / www / xxx"
ServerName www.xxx.com
< / VirtualHost>
# Www.yyy.com
< VirtualHost *>
ServerAdmin yyy@126.com
DocumentRoot "/ var / www / yyy"
ServerName yyy.com
ServerAlias www.yyy.com
< / VirtualHost>
# Configure visible to other sites omitted, Apache listening on port 80, and based on the domain name to distribute requests to different web directories.
Today, the company decided on this server to add a Web site, which has an independent domain name linuxhost.com, use JavaEE development, operation based on Tomcat.
Because Apache listening on port 80 already, so stand-alone Tomcat listening on the port is no longer inevitable. The customer must visit the site in the form of http://www.linuxhost.com, and can not be http://www.linuxhost.com:8080. It must be integrated into the Apache Tomcat below.
Solutions
Apache Tomcat should be integrated into the site, there are two main ways. First, through the AJP protocol, the Apache Tomcat as the worker; the second is to use mod_proxy and mod_proxy_http module forwards the request to Tomcat.
The first way, should be high efficiency, after all, is the Apache Tomcat home products easy to integrate fairly stable.
The second approach, versatility, not only can be forwarded to Tomcat, can also be forwarded to any HTTP server program, such as IIS, another Apache instance.
According to personal preference, I chose the second way.
solution
First, let Tomcat listens on port 8080.
Then modify the httpd.conf.
# Load forwarding module
LoadModule proxy_module modules / mod_proxy.so
LoadModule proxy_http_module modules / mod_proxy_http.so
# To access all linuxhost.com forwarded to Tomcat
< VirtualHost *>
ServerAdmin linuxhost@126.com
ServerName linuxhost.com
ServerAlias www.com
ProxyPass / http: // localhost: 8080 /
ProxyPassReverse / http: // localhost: 8080 /
< / VirtualHost>
So that when the user visits http://www.linuxhost.com, Apache will be replaced by the user and then visit http: // localhost: 8080, and the data retrieved http forwarded to users. This is the Apache reverse proxy, the proxy process for browser clients is imperceptible, to some extent, but also to protect and hide the Tomcat service (because Apache through the network http://127.0.0.1: 8080 access Tomcat service, http: //www.linuxhost.com: 8080 is not visible to the external Internet).
And reverse proxy (Reverse Proxy) corresponding to the Apache forward proxy (Forward Proxy) feature, which requires the browser proxy settings.
Future expansion
In fact, this program has a strong scalability, for the lack of public IP network Web server is very meaningful. For example, someday also need to deploy a Web site based on IIS. The domain is linuxhost.com, run within a Windows machine on the network, IP address 172.16.35.220, IIS listens on port 80. Then you can by Apache reverse proxy functionality to deploy.
< VirtualHost *>
ServerAdmin linuxhost@126.com
ServerName linuxhost.com
ServerAlias www.linuxhost.com
ProxyPass / http://172.16.35.220/
ProxyPassReverse / http://172.16.35.220/
< / VirtualHost> |
|
|
|