將tomcat6連接到apache2
免責聲明:不是伺服器管理員
幾個星期以來,我一直在為此摸不著頭腦(不是一直在意你,因為那會讓人抓狂)。我一直在嘗試將我的 apache2 伺服器連接到我的 tomcat 伺服器,如果有人在導航我的 web 目錄時遇到 *.jsp 或任何servelet,它就會被移交給 tomcat。
我在同一個盒子上同時擁有
Apache2.0 (port 9099)
並Tomcat6 (9089)
在 Debian lenny 上執行。目前,在內容
mod_jk
中啟用:mod_jk.conf``$apacheHOME/mods-enabled/
# Where to find workers.properties JkWorkersFile /etc/apache2/workers.properties # Where to put jk shared memory JkShmFile /var/log/at_jk/mod_jk.shm # Where to put jk logs JkLogFile /var/log/at_jk/mod_jk.log # Set the jk log level [debug/error/info] JkLogLevel info # Select the timestamp log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " # Send servlet for context /examples to worker named worker1 JkMount /*/servlet/* worker1 # Send JSPs for context /examples to worker named worker1 JkMount /*.jsp worker1
我
workers.properties
位於$apacheHOME/
內容:workers.tomcat_home=/var/lib/tomcat6 workers.java_home=/usr/lib/jdk1.6.0_23/db/ worker.list=worker1 ps=/ worker.worker1.port=9081 worker.worker1.host=localhost worker.worker1.type=ajp13
我
web.xml
的 in$tomcatHOME/conf
啟用了以下 servlet<servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-cla$ <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> <init-param> <param-name>fork</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>xpoweredBy</param-name> <param-value>false</param-value> </init-param> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config>
伺服器.xml:
–> –>
<!-- Define an AJP 1.3 Connector on port 8009 --> <Connector port="9081" protocol="AJP/1.3" redirectPort="9088" />
mod_jk.log :
[Mon Feb 21 13:49:35 2011] [2921:3075307264] [info] jk_open_socket::jk_connect.c (566): connect to 127.0.0.1:9081 failed (errno=111) [Mon Feb 21 13:49:35 2011] [2921:3075307264] [info] ajp_connect_to_endpoint::jk_ajp_common.c (869): Failed opening socket to (127.0.0.1:9081) (errno=111) [Mon Feb 21 13:49:35 2011] [2921:3075307264] [error] ajp_send_request::jk_ajp_common.c (1359): (worker1) connecting to backend failed. Tomcat is probably not started or is listening on the wrong port (errno=111) [Mon Feb 21 13:49:35 2011] [2921:3075307264] [info] ajp_service::jk_ajp_common.c (2194): (worker1) sending request to tomcat failed (recoverable), because of error during request sending (attempt=1) [Mon Feb 21 13:49:35 2011] [2921:3075307264] [info] jk_open_socket::jk_connect.c (566): connect to 127.0.0.1:9081 failed (errno=111) [Mon Feb 21 13:49:35 2011] [2921:3075307264] [info] ajp_connect_to_endpoint::jk_ajp_common.c (869): Failed opening socket to (127.0.0.1:9081) (errno=111) [Mon Feb 21 13:49:35 2011] [2921:3075307264] [error] ajp_send_request::jk_ajp_common.c (1359): (worker1) connecting to backend failed. Tomcat is probably not started or is listening on the wrong port (errno=111) [Mon Feb 21 13:49:35 2011] [2921:3075307264] [info] ajp_service::jk_ajp_common.c (2194): (worker1) sending request to tomcat failed (recoverable), because of error during request sending (attempt=2) [Mon Feb 21 13:49:35 2011] [2921:3075307264] [error] ajp_service::jk_ajp_common.c (2212): (worker1) Connecting to tomcat failed. Tomcat is probably not started or is listening on the wrong port [Mon Feb 21 13:49:35 2011] [2921:3075307264] [info] jk_handler::mod_jk.c (2364): Service error=-3 for worker=worker1
埠 9081 似乎有問題,沒有程序正在使用它,所以我認為它配置不正確。雖然我的 tomcat 埠工作正常。
ickronia:/var/log/at_jk# telnet localhost 9081 Trying ::1... Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused ickronia:/var/log/at_jk#
據我所知,apache2、tomcat 和 mod_jk 日誌都顯示為綠色,這並沒有什麼好笑的。然而,每當我導航到一個 jsp 時,它只會顯示 javascript。
儘管傾注了日誌和文件以尋求幫助,但我不確定到底是什麼問題。我是 serverlet 世界的新手。
回答二,因為發生了太多的編輯。這是我的工作設置:-
mod-jk.conf:-
JkWorkersFile /etc/libapache2-mod-jk/workers.properties JkLogFile /var/log/apache2/mod_jk.log JkLogLevel info JkMount /portal worker1 JkMount /portal/* worker1
在啟用的站點中:-
<VirtualHost _default_:443> JkMountCopy On blah blah </VirtualHost>
worker.properties(通常通過負載均衡器,但在這裡簡化):-
worker.list=worker1 worker.worker1.port=9009 worker.worker1.host=host_name worker.worker1.type=ajp13
tomcat server.xml:-
<?xml version='1.0' encoding='utf-8'?> <Server port="9005" shutdown="SHUTDOWN"> <!-- cut --> <Service name="Catalina"> <Connector port="9080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="9443" /> <Connector port="9443" protocol="HTTP/1.1" SSLEnabled="true" keystoreFile="<path_to_keystore>.ks" kestorePass="<password for keystore>" maxThreads="200" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> <Connector port="9009" protocol="AJP/1.3" redirectPort="9443" /> <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1"> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> </Host> </Engine> </Service> </Server>
所以 Tomcat 在 9080 上偵聽 http,在 9443 上偵聽 https,在 9009 上偵聽 ajp。
Apache 正在偵聽 https 埠 443。發送到該伺服器上 /portal 上下文的任何內容都將通過 mod_jk worker1 發送到通過 ajp 轉發到 tomcat 的任何內容。
希望這可以幫助!