我有一个Apache服务器使用mod_proxy_ajp有Jboss / Tomcat5.5处理所有请求。 这里是我如何configurationApache 2.2.17,并在大多数情况下,它的工作原理:
# Proxy pass all work to Tomcat, mod_jk 1.2.31 <Location /> # ProxyPass / http://localhost:8080/ ProxyPass ajp://localhost:8009/ ProxyPassReverse ajp://localhost:8009/ </Location> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} # and , to handle the redirect of the root dir Redirect permanent / https://%{HTTP_HOST}%/myapp
不幸的是, 虽然启用了ProxyPass ,但我无法获得任何mod_rewrite规则的工作,除了上面的。 我该如何处理这种情况?
我试图创build一个类似于这个RedirectMatch规则的重写规则(只有当我closuresProxyPass时才起作用):
RedirectMatch ^/(?i)myagency "/myapp?agency=MyAgency%20LA"
另外,我发现另一个奇怪的东西,这可能会提供我的问题的见解,在这里张贴。
好吧,我终于明白了自己。 AJP协议的工作方式与HTTPtypes规则不同,所以它们不会混合。 为了解决这个问题,我不得不停止将所有事情redirect到AJP,而只是使用AJPredirect应用程序。 答案是:
# don't ProxyPass through the "/" dir location, # since it breaks the mod_rewrite rules <Location /myapp> ProxyPass ajp://localhost:8009/myapp ProxyPassReverse ajp://localhost:8009/myapp </Location> RewriteEngine On # rule to redirect from http to https RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} # rule to redirect / to the app context since nothing is served at / Redirect / /myapp?name= # supplemental rules to handle URI shortcuts RedirectMatch ^/(?i)name1 /myapp?name=NameOne RedirectMatch ^/(?i)name2 "/myapp?name=Name%20Two"
您可以使用[P]代理请求,将ProxyPass和ProxyPassReverse指令转换为RewriteRule指令,如下所示:
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteRule (.*) ajp://localhost:8009/$1 [P]
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule rewrite_module modules/mod_rewrite.so RewriteEngine On RewriteRule ^/$ /index.html [L] # RequestHeader set REMOTE_USER %{LA-U:REMOTE_USER}e RewriteCond %{REQUEST_URI} !^/fusioncp ReWriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteRule ^(.*) ajp://localhost:18009$1 [P]