Centos
帶有 AJP 連接器的 Tomcat 管理器中的 404
我正在嘗試使用 Apache mod_jk、SSL 和 AJP 連接器在 CentOS 6 上配置 Tomcat 7。
JK 模組安裝在 Apache 下:
$ sudo httpd -M | grep jk jk_module (shared) Syntax OK
Tomcat 配置了 AJP 連接器,如下所示:
<?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>
workers.properties 文件配置如下:
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
Apache 配置為通過虛擬主機為 Tomcat webapps 提供服務,如下所示:
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 webmaster@my.domain.com 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 webmaster@my.domain.com 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>
Tomcat 和管理器應用程序已啟動並執行,沒有明顯錯誤:
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
然而,當我嘗試在https://xxxx/manager載入管理器應用程序時,我收到 404 錯誤。我知道請求正在通過 Tomcat,因為 URL 重定向到 /manager/html,我得到的是 Tomcat 404 而不是 Apache 404。Apache 日誌顯示請求:
[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
mod_jk 的日誌也顯示了請求:
[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 提供了更多資訊:
$ 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
我被這個難住了——一切似乎都在正常執行,但在某個地方,通信正在中斷。任何見解將不勝感激,謝謝!
問題原來是 APR 庫的建構失敗。我使用 Ansible 部署 Tomcat,“shell”命令中的一個明顯錯誤導致 APR 配置靜默失敗。
可以在此處查看有關 Ansible 的此問題的詳細資訊:Ansible playbook not working try to run make & configure with complex switch