2

I have a Apache server using mod_proxy_ajp to have Jboss/Tomcat5.5 handling all the requests. Here is how I configured Apache 2.2.17, and for the most part, it works:

# 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

Unfortunately, while ProxyPass is enabled, I am not able to get any mod_rewrite rules to work except for the ones above. How do I handle this situation?

I am trying to create a rewrite rule similar to this RedirectMatch rule (which only works if I turn off ProxyPass):

RedirectMatch ^/(?i)myagency   "/myapp?agency=MyAgency%20LA"

Also, another wierd thing I found, which may provide insight to my issue, is posted here .

djangofan
  • 4,172
  • 10
  • 45
  • 59

3 Answers3

2

You could convert your ProxyPass and ProxyPassReverse directives to RewriteRule directives instead, using [P] to proxy the request, like so:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule (.*) ajp://localhost:8009/$1 [P]
walkeran
  • 356
  • 1
  • 5
  • Using the [P] option of mod_rewrite didn't work for me. The only way it will really proxy for me is by using the ProxyPass rule of mod_proxy_ajp . I think this makes sense since [P] was made for proxies in general, and not for the special case of AJP, right? – djangofan Apr 28 '11 at 22:25
  • I'm actually not positive, as I've never applied this to AJP specifically. I know that mod_rewrite actually uses mod_proxy to carry out its proxying. I kinda went out on a limb, and assumed that any functionality added to mod_proxy by mod_proxy_ajp (ie, handling ajp:// URLs) would also be gained by mod_rewrite and it's proxying. I'll do a little more poking around :) – walkeran Apr 29 '11 at 01:46
  • I edited my question (above) to highlight the difference between http/mod_proxy vs. ajp/mod_proxy_ajp . – djangofan Apr 29 '11 at 02:10
2

Ok, I finally figured it out for myself. AJP protocol works differently than HTTP type rules and so they wouldn't mix. To solve it, I had to stop redirecting everything to AJP and instead just redirect the application only using AJP. Here was the answer:

# 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"
djangofan
  • 4,172
  • 10
  • 45
  • 59
-1
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]
HBruijn
  • 72,524
  • 21
  • 127
  • 192