Estou tentando configurar o Tomcat 7 no CentOS 6 com o Apache mod_jk, SSL e um conector AJP.
O módulo JK está instalado no Apache:
$ sudo httpd -M | grep jk
jk_module (shared)
Syntax OK
O Tomcat é configurado com um conector AJP da seguinte forma:
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" packetSize="65536" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
O arquivo workers.properties é configurado da seguinte forma:
worker.list=default,lb,jk-status
worker.default.type=ajp13
worker.default.host=x.x.x.x
worker.default.port=8009
worker.lb.type=lb
worker.lb.balance_workers=default
worker.jk-status.type=status
O Apache é configurado para atender às aplicações web do Tomcat por meio de um host virtual da seguinte forma:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/httpd/conf/workers.properties
JkShmFile /var/log/httpd/mod_jk.shm
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +RejectUnsafeURI +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMountCopy All
<VirtualHost x.x.x.x:80>
ServerAdmin [email protected]
ServerName my.domain.com
ServerAlias www.my.domain.com
# Always redirect to SSL
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
<VirtualHost x.x.x.x:443>
ServerAdmin [email protected]
ServerName my.domain.com:443
ServerAlias www.my.domain.com
ErrorLog /var/log/httpd/ssl_my.domain.com_error_log
LogFormat "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %>s %b" ssl_log
CustomLog /var/log/httpd/ssl_my.domain.com_access_log ssl_log
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/my.domain.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/my.domain.com.key
SSLCertificateChainFile /etc/pki/tls/certs/tw-chain.crt
JkMountCopy On
JkMount /manager default
JkMount /manager/* default
</VirtualHost>
O Tomcat e o aplicativo gerenciador estão funcionando sem erros aparentes:
Sep 11, 2014 12:29:18 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.31 using APR version 1.3.9.
Sep 11, 2014 12:29:18 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Sep 11, 2014 12:29:18 PM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized (OpenSSL 1.0.1e 11 Feb 2013)
Sep 11, 2014 12:29:18 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-apr-8009"]
Sep 11, 2014 12:29:18 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 512 ms
Sep 11, 2014 12:29:18 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 11, 2014 12:29:18 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.55
Sep 11, 2014 12:29:34 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/share/apache-tomcat-7.0.55/webapps/manager
Sep 11, 2014 12:29:34 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/share/apache-tomcat-7.0.55/webapps/manager has finished in 146 ms
Sep 11, 2014 12:29:34 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-apr-8009"]
Sep 11, 2014 12:29:34 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 15586 ms
No entanto, quando tento carregar o aplicativo gerenciador no link , recebo um erro 404. Eu sei que a solicitação está chegando ao Tomcat, porque a URL redireciona para / manager / html, e eu recebo o Tomcat 404 em vez do Apache 404. Os logs do Apache mostram as solicitações:
[17/Sep/2014:15:44:05 -0400] x.x.x.x TLSv1.2 AES256-SHA256 "GET /manager/html HTTP/1.1" 404 975
[17/Sep/2014:15:44:06 -0400] x.x.x.x TLSv1.2 AES256-SHA256 "GET /manager/html HTTP/1.1" 404 975
Logs para mod_jk mostram os pedidos também:
[Wed Sep 17 15:43:54 2014] [22722:140360872835040] [info] init_jk::mod_jk.c (3383): mod_jk/1.2.40 initialized
[Wed Sep 17 15:44:05 2014] default x.x.x.x 0.001380
[Wed Sep 17 15:44:06 2014] default x.x.x.x 0.001489
Curl fornece um pouco mais de informação:
$ curl -kLI https://x.x.x.x/manager
HTTP/1.1 302 Found
Date: Wed, 17 Sep 2014 18:50:22 GMT
Location: https://x.x.x.x/manager/
Content-Type: text/plain; charset=UTF-8
HTTP/1.1 302 Found
Date: Wed, 17 Sep 2014 18:50:22 GMT
Set-Cookie: JSESSIONID=D4B4A040BE7D4724A7D25B7F63FC2B92; Path=/manager/; Secure; HttpOnly
Location: https://x.x.x.x/manager/html;jsessionid=D4B4A040BE7D4724A7D25B7F63FC2B92
Content-Type: text/html;charset=ISO-8859-1
HTTP/1.1 404 Not Found
Date: Wed, 17 Sep 2014 18:50:22 GMT
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1063
Eu estou perplexo com este - tudo parece estar funcionando corretamente, mas em algum lugar ao longo da linha a comunicação está quebrando. Qualquer ideia seria muito apreciada, obrigado!