我有一个场景,其中对 Tomcat 服务器(应用服务器)的所有请求都应通过 Apache 2.2(Web 服务器)。这两个服务器位于两台不同的机器上。出于安全原因,这两台机器不在同一个域或网络上。
我必须使用如下所示的虚拟主机设置,因为它已被我公司的其他开发人员使用过,并且经过了全面测试并且运行良好。
<VirtualHost *:*>
#Full Computer Name with port if its not 80
ServerName Full_Name_OF_Computer
ServerAlias Full_Name_OF_Computer
LogFormat "%h %l %u %t \"%r\" %s %b %D" app
CustomLog logs/app-access.log app
SSLProxyEngine On
RewriteEngine on
RewriteLogLevel 5
RewriteLog logs/rewrite.log
# Root URL handling
RewriteRule ^\/app\/?$ /app/launch.jsp [R,L]
RewriteRule ^\/app\/?$ ajp://Full_Name_OF_Computer:8009/app [P,L]
# Dynamic content
RewriteRule ^/app/(.+\.(?:jsp|do|rpc).*)$ ajp://Full_Name_OF_Computer:8009/app/$1 [P,L]
# This must be the location where application is deployed
# SHOULD THIS BE THE LOCATION WITH IN THE APPLICATION SEVER OR THE LOCATION PATH TO THE APPLICATION SERVER FROM WEB SERVER??
Alias /app "D:\apache-tomcat-7.0.63\webapps\app"
<Directory "D:\apache-tomcat-7.0.63\webapps\app">
Options FollowSymLinks
AllowOverride None
Allow from all
ExpiresActive on
ExpiresDefault "access plus 2 months"
ExpiresByType application/x-javascript "access plus 2 months"
ExpiresByType application/javascript "access plus 2 months"
ExpiresByType text/javascript "access plus 2 months"
ExpiresByType text/css "access plus 2 months"
ExpiresByType image/gif "access plus 2 months"
ExpiresByType image/jpeg "access plus 2 months"
ExpiresByType image/png "access plus 2 months"
ExpiresByType image/x-icon "access plus 2 months"
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/json application/x-javascript
</Directory>
</VirtualHost>
如果我在同一台机器上安装了 apache 和 tomcat 服务器,那么这对我来说没问题。但是,如果我在不同的机器上安装了 Apache 和 Tomcat 服务器(根据需要),那么我对 HTTPD.conf 进行了一些更改,之后我无法通过 Apache 访问应用程序。但是可以通过 Appplication URL 从 WebServer 访问该应用程序(使用端口 8080)。
有人可以帮我指出我做错的事情吗?
在更改 Tomcat 上的 WebServerFullName、ApplicationServerFullName 和应用程序部署文件夹的网络路径后,新的虚拟主机设置如下:
<VirtualHost *:*>
#Full Computer Name with port if its not 80
ServerName Web_Server_Ful_Name
ServerAlias Web_Server_Ful_Name
LogFormat "%h %l %u %t \"%r\" %s %b %D" app
CustomLog logs/app-access.log app
SSLProxyEngine On
RewriteEngine on
RewriteLogLevel 5
RewriteLog logs/rewrite.log
# Root URL handling
RewriteRule ^\/app\/?$ /app/launch.jsp [R,L]
RewriteRule ^\/app\/?$ ajp://ApplicationServerFullName:8009/app [P,L]
# Dynamic content
RewriteRule ^/app/(.+\.(?:jsp|do|rpc).*)$ ajp://ApplicationServerFullName:8009/app/$1 [P,L]
# This must be the location where application is deployed
# SHOULD THIS BE THE LOCATION WITH IN THE APPLICATION SEVER OR THE LOCATION PATH TO THE APPLICATION SERVER FROM WEB SERVER??
Alias /app "\\ApplicationServerFullName\cim$\apache-tomcat-7.0.63\webapps\app"
<Directory "\\ApplicationServerFullName\cim$\apache-tomcat-7.0.63\webapps\app">
Options FollowSymLinks
AllowOverride None
Allow from all
ExpiresActive on
ExpiresDefault "access plus 2 months"
ExpiresByType application/x-javascript "access plus 2 months"
ExpiresByType application/javascript "access plus 2 months"
ExpiresByType text/javascript "access plus 2 months"
ExpiresByType text/css "access plus 2 months"
ExpiresByType image/gif "access plus 2 months"
ExpiresByType image/jpeg "access plus 2 months"
ExpiresByType image/png "access plus 2 months"
ExpiresByType image/x-icon "access plus 2 months"
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/json application/x-javascript
</Directory>
</VirtualHost>
我对 Tomcat 上应用程序部署文件夹的网络路径有疑问,因为两台计算机不在同一个网络上,网络管理员不得不给我一个奇怪的路径,考虑到其中的美元符号 ($),\ApplicationServerFullName\cim$\apache-tomcat-7.0.63\webapps\app (虽然可以通过浏览器从 WebServer 访问)
其他详细信息包括:
- Apache2.2
- Apache-tomcat-7.0.63-windows-x64
- Windows Server 2012 适用于 Web 服务器和应用程序服务器。
Tomcat Server.xml AJP 设置:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
错误日志:
[Fri Aug 14 18:27:07 2015] [debug] mod_proxy_ajp.c(45): proxy: AJP: canonicalising URL //ApplicationServerFullName:8009/app/launch.jsp
[Fri Aug 14 18:27:07 2015] [debug] proxy_util.c(1532): [client 10.16.1.3] proxy: *: found reverse proxy worker for ajp://ApplicationServerFullName:8009/app/launch.jsp
[Fri Aug 14 18:27:07 2015] [debug] mod_proxy.c(1036): Running scheme ajp handler (attempt 0)
[Fri Aug 14 18:27:07 2015] [debug] mod_proxy_ajp.c(726): proxy: AJP: serving URL ajp://ApplicationServerFullName:8009/app/launch.jsp
[Fri Aug 14 18:27:07 2015] [debug] proxy_util.c(2018): proxy: AJP: has acquired connection for (*)
[Fri Aug 14 18:27:07 2015] [debug] proxy_util.c(2074): proxy: connecting ajp://ApplicationServerFullName:8009/app/launch.jsp to ApplicationServerFullName:8009
[Fri Aug 14 18:27:07 2015] [debug] proxy_util.c(2200): proxy: connected /app/launch.jsp to ApplicationServerFullName:8009
[Fri Aug 14 18:27:07 2015] [debug] proxy_util.c(2451): proxy: AJP: fam 2 socket created to connect to *
[Fri Aug 14 18:27:07 2015] [debug] ajp_header.c(224): Into ajp_marshal_into_msgb
[Fri Aug 14 18:27:07 2015] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[0] [Accept] = [text/html, application/xhtml+xml, */*]
[Fri Aug 14 18:27:07 2015] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[1] [Accept-Language] = [nl-NL]
[Fri Aug 14 18:27:07 2015] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[2] [User-Agent] = [Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko]
[Fri Aug 14 18:27:07 2015] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[3] [Accept-Encoding] = [gzip, deflate]
[Fri Aug 14 18:27:07 2015] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[4] [Host] = [Web_Server_Ful_Name]
[Fri Aug 14 18:27:07 2015] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[5] [Connection] = [Keep-Alive]
[Fri Aug 14 18:27:07 2015] [debug] ajp_header.c(461): ajp_marshal_into_msgb: Done
[Fri Aug 14 18:27:07 2015] [debug] mod_proxy_ajp.c(270): proxy: APR_BUCKET_IS_EOS
[Fri Aug 14 18:27:07 2015] [debug] mod_proxy_ajp.c(275): proxy: data to read (max 8186 at 4)
[Fri Aug 14 18:27:07 2015] [debug] mod_proxy_ajp.c(290): proxy: got 0 bytes of data
[Fri Aug 14 18:27:07 2015] [error] (OS 10054)An existing connection was forcibly closed by the remote host. : ajp_ilink_receive() can't receive header
[Fri Aug 14 18:27:07 2015] [error] ajp_read_header: ajp_ilink_receive failed
[Fri Aug 14 18:27:07 2015] [error] (120006)APR does not understand this error code: proxy: read response failed from (null) (*)
[Fri Aug 14 18:27:07 2015] [debug] proxy_util.c(2036): proxy: AJP: has released connection for (*)
重写日志
10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] [Web_Server_Ful_Name/sid#79a028][rid#7aed50/initial] (2) init rewrite engine with requested uri /app/launch.jsp
10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] [Web_Server_Ful_Name/sid#79a028][rid#7aed50/initial] (3) applying pattern '^\\/app\\/?$' to uri '/app/launch.jsp'
10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] [Web_Server_Ful_Name/sid#79a028][rid#7aed50/initial] (3) applying pattern '^\\/app\\/?$' to uri '/app/launch.jsp'
10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] [Web_Server_Ful_Name/sid#79a028][rid#7aed50/initial] (3) applying pattern '^/app/(.+\\.(?:jsp|do|rpc).*)$' to uri '/app/launch.jsp'
10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] [Web_Server_Ful_Name/sid#79a028][rid#7aed50/initial] (2) rewrite '/app/launch.jsp' -> 'ajp://ApplicationServerFullName:8009/app/launch.jsp'
10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] [Web_Server_Ful_Name/sid#79a028][rid#7aed50/initial] (2) forcing proxy-throughput with ajp://ApplicationServerFullName:8009/app/launch.jsp
10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] [Web_Server_Ful_Name/sid#79a028][rid#7aed50/initial] (1) go-ahead with proxy request proxy:ajp://ApplicationServerFullName:8009/app/launch.jsp [OK]
访问日志
10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] "GET /app/launch.jsp HTTP/1.1" 503 323 0
有人可以帮我解决这个问题吗,因为我没有时间实现这个功能,而且我在网上查找了很多类似的问题,但我找不到任何解决方案。
提前致谢。
答案1
该错误是由于 tomcat 的 AJP 端口无法从外部访问造成的。
打开端口后,我只是将静态内容放在 Apache 托管的服务器上,因此不需要在 WebServer 上映射网络路径。