Pergunta

Como resultado , erros horríveis horríveis , nós' ve mudou a forma como nos conectamos Apache para Tomcat. Estávamos usando mod_jk:

JkMount /path ajp13

Agora, estamos usando mod_proxy_ajp:

ProxyPass /path ajp://localhost:8009/path
ProxyPassReverse /path ajp://localhost:8009/path

No entanto, há uma característica que JkMount oferecido, mas ProxyPass não: a capacidade de selecionar em tipos de arquivo. Isto tornou possível para arquivos html de proxy, mas não imagens - em outras palavras, para deixar o agradável rápido Apache servir o material estático e recorrer ao lento Tomcat apenas para o material dinâmico

.
JkMount /*.html ajp13

Existe alguma maneira de conseguir isso com ProxyPass? Possivelmente usando uma directiva <Location> circundante ou algo parecido?

Foi útil?

Solução

Use ProxyPassMatch :

ProxyPassMatch ^/(path/.*\.html)$ ajp://localhost:8009/$1

Editado: correção de Marcus Downing

Outras dicas

Não é o seu problema, mas algo a se observar ao usar essa configuração. Enquanto estiver usando apache mod_proxy para se conectar ao Tomcat meu log de erro estava mostrando ligações interrompidas sob carga moderada. Adicionando este para httpd.conf resolvido meus problemas.

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1

O post de kmkaplan é a resposta certa, mas deu-me o erro:

Syntax error on line 32 of .../httpd-vhosts.conf:
ProxyPass Unable to parse URL

Ele trabalhou quando eu mudei a directiva para ler:

ProxyPathMatch ^/(path/.*\.html)$ ajp://localhost:8009/$1

Eu só posso supor que colocar o $1 ao lado do número da porta 8009 foi confundindo-o.

Nós usamos o seguinte para deixar Apache servir imagens e definir razoável expira cabeçalhos:

<Virtualhost *:80>
    ServerName domain.com
    ServerAlias *.domain.com

    Alias /img/ /var/www/domain/img/
    <Directory /var/www/domain/img/>
        ExpiresActive On
        ExpiresByType image/gif "access plus 1 months"
        ExpiresByType image/jpg "access plus 1 months"
        ExpiresByType image/jpeg "access plus 1 months"
        ExpiresByType image/png "access plus 1 months"
        ExpiresByType image/x-icon "access plus 1 months"
        ExpiresByType image/ico "access plus 1 months"
        # This will prevent apache from having to check for a .htaccess file on each request.
        AllowOverride None
        # Allow symlinks. Otherwise, apache will make a separate call on each filename to ensure it is not a symlink.
        Options +FollowSymLinks -SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    # Prevent domain.com/img from being served by Tomcat
    ProxyPass /img !

    # Pass all other requests to Tomcat
    ProxyPass / ajp://localhost:8009/

    # 1. Note that usually no ProxyPassReverse directive is necessary. The AJP request includes
    #    the original host header given to the proxy, and the application server can be expected to
    #    generate self-referential headers relative to this host, so no rewriting is necessary. 
    # 2. If you still want to use it, read this first:
    #    http://www.humboldt.co.uk/2009/02/the-mystery-of-proxypassreverse.html
    # ProxyPassReverse / http://domain.com/
</Virtualhost>

No entanto, como você pode ver, nós armazenar imagens fora do nosso aplicativo Tomcat. Eu não sei se ele também funciona para imagens dentro do aplicativo.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top