Obscurecendo o caminho do contexto do tomcat no URL

3

Eu configurei um proxy reverso do Apache para o Tomcat que está funcionando, pois eu posso carregar meu URL e obter conexão com o back-end do Tomcat. O que estou tentando fazer agora é reescrever a URL que um usuário vê no navegador. Aqui está o meu código -

LoadModule      proxy_html_module       modules/mod_proxy_html.so
LoadModule  proxy_ajp_module    modules/mod_proxy_ajp.so

# DON'T TURN ProxyRequests ON!  Bad things will happen
ProxyRequests off

# Enabling mod_proxy_html
ProxyHTMLEnable On
ProxyHTMLLogVerbose On
LogLevel Debug

SSLProxyEngine on

# Setup mod_proxy_ajp load balancer to the 2 happ hosts
<Proxy balancer://happcluster>
BalancerMember ajp://happ01.domain.com:8009 loadfactor=1
BalancerMember ajp://happ02.domain.com:8009 loadfactor=1
ProxySet lbmethod=bytraffic
ProxySet stickysession=JSESSIONID
</Proxy>

# rewrite setup

RewriteEngine   On
RewriteLog      /var/log/httpd/rewrite_log
RewriteLogLevel        8

RewriteCond     %{HTTP_HOST} !^www.* [NC]
RewriteCond     %{HTTP_HOST} ^app\.domain\.com$ [NC]
RewriteCond     %{REQUEST_URI} !^/app1/.*$
RewriteCond     %{REQUEST_URI} !^.*\.ico$ [NC]
RewriteRule     ^(/.*) balancer://happcluster/app$1 [P]

# Necessary to have mod_proxy_html do the rewriting
RequestHeader      unset  Accept-Encoding

# Be prepared to rewrite the HTML/CSS files as they come back
# from Tomcat
SetOutputFilter proxy-html
SetOutputFilter INFLATE;DEFLATE

# Rewrite JavaScript and CSS files in addition to HTML files
ProxyHTMLExtended On

# Output Strict XHTML (add "Legacy" to the end of the line below
# to output Transitional XHTML)
ProxyHTMLDoctype XHTML

# Rewrite HTTP headers and HTML/CSS links for everything else
ProxyPassReverse /app1/ /
ProxyPassReverseCookiePath /app1/ /
ProxyHTMLURLMap /app1/ /

O que acontece é que quando eu digito link em um navegador, o URL é reescrito para link .....

Estou usando mod_proxy_ajp para carregar as solicitações de saldo em dois servidores tomcat de back-end e isso parece estar funcionando.

Alguma idéia?

EDITAR

Aqui está um trecho do meu registro de reescrita que mostra o proxy para o back-end -

[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (2) init rewrite engine with requested uri /
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (3) applying pattern '^(/.*)' to uri '/'
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (4) RewriteCond: input='app.domain.com' pattern='!^www.*' [NC] => matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (4) RewriteCond: input='app.domain.com' pattern='^app\.domain\.com$' [NC] => matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (4) RewriteCond: input='/' pattern='!^/app1/.*$' => matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (4) RewriteCond: input='/' pattern='!^.*\.ico$' [NC] => matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (2) rewrite '/' -> 'balancer://happcluster/app1/'
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (2) forcing proxy-throughput with balancer://happcluster/app1/
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d73c0/initial] (1) go-ahead with proxy request proxy:balancer://happcluster/app1/ [OK]
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (2) init rewrite engine with requested uri /app1/login.jsp;jsessionid=F6D9765F6A737DB373D9C3AA60211B68.worker1
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (3) applying pattern '^(/.*)' to uri '/app1/login.jsp;jsessionid=F6D9765F6A737DB373D9C3AA60211B68.worker1'
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (4) RewriteCond: input='app.domain.com' pattern='!^www.*' [NC] => matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (4) RewriteCond: input='app.domain.com' pattern='^app\.domain\.com$' [NC] => matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (4) RewriteCond: input='/app1/login.jsp;jsessionid=F6D9765F6A737DB373D9C3AA60211B68.worker1' pattern='!^/app1/.*$' => not-matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (3) applying pattern '^(/.*)' to uri '/app1/login.jsp;jsessionid=F6D9765F6A737DB373D9C3AA60211B68.worker1'
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (4) RewriteCond: input='app.domain.com' pattern='!^www.*' [NC] => matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (4) RewriteCond: input='app.domain.com' pattern='^app\.domain\.com$' [NC] => matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (4) RewriteCond: input='/app1/login.jsp;jsessionid=F6D9765F6A737DB373D9C3AA60211B68.worker1' pattern='!^/app1/.*$' => not-matched
[app.domain.com/sid#2b0c5d2d4ef0][rid#2b0c5d0d53b0/initial] (1) pass through /app1/login.jsp;jsessionid=F6D9765F6A737DB373D9C3AA60211B68.worker1

E um snippet do meu access_log -

"GET /app1/login.jsp HTTP/1.1" 200 607
"GET / HTTP/1.1" 302 -
"GET /app1/login.jsp;jsessionid=F6D9765F6A737DB373D9C3AA60211B68.worker1 HTTP/1.1" 200 607
    
por Matthew Schmitt 13.07.2012 / 18:56

1 resposta

1

Esse tipo de coisa está fadado ao fracasso, pois o Tomcat também incorpora URLs auto-relativos no HTML que ele produz. Há um módulo de terceiros para corrigir isso também, mas até mesmo o uso de regras de reescrita é geralmente um sinal de que você está fazendo a coisa errada. A única técnica que realmente funciona é usar o mesmo URL no Apache e no Tomcat. Nesse caso, basta descobrir quais são as URLs de contexto do Tomcat e ProxyPass todas elas.

Eu concordo com Shane Madden que você deve procurar em mod_proxy_ajp em vez de mod_jk. É milhas mais fácil de configurar, faz exatamente a mesma coisa e faz parte do Apache, não uma peça separada.

    
por 15.07.2012 / 03:34