描述
内部Tomcat服务器侦听8080端口上的Web应用程序:
"http://internal:8080/foo-webservice/"
"http://internal:8080/foo-website/"外部Apache服务器代理子域的请求:
"http://foo.domain.com/"任何子域根目录的请求将被代理到Tomcat上的foo-website Web应用程序。
其他请求将被代理到适当的路径/ Web应用程序。
用例A
请求:
"http://foo.domain.com/index.html"代理到:
"http://internal:8080/foo-website/index.html"
用例B
请求:
"http://foo.domain.com/webservice/listener.html?param1=foo¶m2=bar"代理到:
"http://internal:8080/foo-webservice/listener.html?param1=foo¶m2=bar"
VirtualHost定义
Current virtual host definition which satisfies Use Case B:
<VirtualHost *:80> ServerName foo.domain.com ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ErrorLog /var/log/apache2/foo_error.log LogLevel warn CustomLog /var/log/apache2/foo_access.log combined # RewriteRules # ? # ProxyPass ProxyPreserveHost On ProxyPass / http://internal:8080/ ProxyPassReverse / http://internal:8080/ </VirtualHost>
尝试 1
# RewriteRules
RewriteEngine On
RewriteRule ^/(.*) http://internal:8080/foo-website/$1 [P]
- 使用案例A已得到满足
- 使用案例B失败
尝试2
# RewriteRules
RewriteEngine On
RewriteRule ^/$ http://internal:8080/foo-website/$1 [P]
- 满足使用案例B
- 使用案例A不完全满足
- 在foo-website中加载了index.html,但js、img或css文件夹中的任何文件都没有被加载。