我确信答案很简单,但我却抓狂不已。我正在使用 Apache 2.4 和 Tomcat 8.5.23 在新的 Ubuntu 16 系统上重建一个 apache httpd + tomcat 站点。我正在运行 tomcat,ajp13 连接器似乎正在运行,但请求http://abilities.tld/给出 404。404 在 mod_jk.log 中显示为源自 tomcat,因此它不是简单的 httpd 404。
简化的 vhost 配置
<VirtualHost 1.1.1.1:80>
DocumentRoot "/home/user/subdir/html"
ServerName abilities.tld
ServerAlias www.abilities.tld
<Directory "/home/user/subdir/html">
allow from all
Options ExecCGI Includes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
SuexecUserGroup user user
JkMount /* ajp13
#Directives to enable Apache to continue serving applications dependent on it.
SetEnvIf Request_URI "/webmail*" no-jk
SetEnvIf Request_URI "/mail*" no-jk
SetEnvIf Request_URI "/awstats*" no-jk
SetEnvIf Request_URI "/myadmin*" no-jk
SetEnvIf Request_URI "/pgadmin*" no-jk
SetEnvIf Request_URI "/cgi-bin*" no-jk
#DirectoryIndex /abilities
`
Apache vhost 日志 2.2.2.2 - - [16/Nov/2017:14:08:18 +1100] “GET / HTTP/1.1” 404 164
参观http://1.1.1.1:8080/主机管理器/html运行良好并显示虚拟主机
Catalina 日志显示 WAR 的启动部署符合预期。
在 server.xml 中
<Host appBase="/home/user/subdir/html" name="abilities.tld" unpackWARs="true" autoDeploy="true">
<Alias>www.abilities.tld</Alias>
<Context path="" docBase="abilities" debug="0" reloadable="true"/>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="abilities.tld" suffix=".txt" timestamp="true"/>
</Host>
并在 /var/log/apache2/mod_jk.log 中
[Thu Nov 16 14:46:53.105 2017] [26722:140421309081472] [debug] map_uri_to_worker_ext::jk_uri_worker_map.c (1179): Attempting to map URI '/' from 1 maps
[Thu Nov 16 14:46:53.105 2017] [26722:140421309081472] [debug] find_match::jk_uri_worker_map.c (978): Attempting to map context URI '/*=ajp13' source 'JkMount'
[Thu Nov 16 14:46:53.105 2017] [26722:140421309081472] [debug] find_match::jk_uri_worker_map.c (991): Found a wildchar match '/*=ajp13'
[Thu Nov 16 14:46:53.105 2017] [26722:140421309081472] [debug] jk_handler::mod_jk.c (2823): Into handler jakarta-servlet worker=ajp13 r->proxyreq=0
[Thu Nov 16 14:46:53.105 2017] [26722:140421309081472] [debug] wc_get_worker_for_name::jk_worker.c (120): found a worker ajp13
[Thu Nov 16 14:46:53.105 2017] [26722:140421309081472] [debug] wc_get_name_for_type::jk_worker.c (304): Found worker type 'ajp13'
[Thu Nov 16 14:46:53.105 2017] [26722:140421309081472] [debug] init_ws_service::mod_jk.c (1196): Service protocol=HTTP/1.1 method=GET ssl=false host=(null) addr=1.178.147.184 name=abilities.tld port=80 auth=(null) user=(null) laddr=103.18.42.17 raddr=1.178.147.184 uaddr=1.178.147.184 uri=/
[Thu Nov 16 14:46:53.105 2017] [26722:140421309081472] [debug] ajp_get_endpoint::jk_ajp_common.c (3351): (ajp13) acquired connection pool slot=0 after 0 retries
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] ajp_marshal_into_msgb::jk_ajp_common.c (684): (ajp13) ajp marshaling done
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] ajp_service::jk_ajp_common.c (2586): processing ajp13 with 2 retries
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] jk_shutdown_socket::jk_connect.c (932): About to shutdown socket 37 [127.0.0.1:50968 -> 127.0.0.1:8009]
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] jk_is_input_event::jk_connect.c (1406): error event during poll on socket 37 [errno=107] (event=24)
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] jk_shutdown_socket::jk_connect.c (1016): Shutdown socket 37 [127.0.0.1:50968 -> 127.0.0.1:8009] and read 0 lingering bytes in 0 sec.
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] ajp_send_request::jk_ajp_common.c (1639): (ajp13) failed sending request, socket 37 is not connected any more (errno=0)
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] ajp_abort_endpoint::jk_ajp_common.c (821): (ajp13) aborting endpoint with socket 37
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] ajp_send_request::jk_ajp_common.c (1717): (ajp13) no usable connection found, will create a new one, detected by connect check (1), cping (0), send (0).
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] jk_open_socket::jk_connect.c (675): socket TCP_NODELAY set to On
[Thu Nov 16 14:46:53.106 2017] [26722:140421309081472] [debug] jk_open_socket::jk_connect.c (799): trying to connect socket 37 to 127.0.0.1:8009
[Thu Nov 16 14:46:53.107 2017] [26722:140421309081472] [debug] jk_open_socket::jk_connect.c (825): socket 37 [127.0.0.1:58717 -> 127.0.0.1:8009] connected
[Thu Nov 16 14:46:53.107 2017] [26722:140421309081472] [debug] ajp_connection_tcp_send_message::jk_ajp_common.c (1267): sending to ajp13 pos=4 len=704 max=8192
......
[Thu Nov 16 14:46:53.172 2017] [26722:140421309081472] [debug] ajp_unmarshal_response::jk_ajp_common.c (739): (ajp13) status = 404
我还能在哪里查找为什么 tomcat 给出 404 错误?
谢谢
答案1
因此答案是 tomcat vhost 加载失败,而 web 请求由 localhost(默认)vhost 提供服务。因此出现 404。