0

I have a scenario where all the requests to the Tomcat Server (Application Server) should go through the Apache 2.2 (Web server). Both the servers are on 2 different machines. The 2 machines are not on the same domain or network due to security reasons.

I have to use a Virtual Host setting like below because this had already been used by other developers in my company and its fully tested and works fine.

<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>

This works fine for me if I have install both the apache and tomcat server on the same machine. However, if I install the Apache and Tomcat Server on different machines (As Required) then I make few changes to the HTTPD.conf and after that I am unable to access the Application through Apache. The application is accessible from the WebServer through the Appplication URL though (using port 8080).

Can somebody please help me in pointing out what I am doing wrong?

After changing the WebServerFullName, the ApplicationServerFullName and the Network Path to Application Deployment Folder on Tomcat, the New Virtual Host Settings are:

<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>

I have my doubt on the Network Path to the application deployment Folder on Tomcat because as the 2 computers are not on the same Network, the network administrator had to give me a Strange Path considering the DOLLAR ($) sign in it, \ApplicationServerFullName\cim$\apache-tomcat-7.0.63\webapps\app (Which is accessible from WebServer through the browser though)

Other Details Are:

  1. Apache2.2
  2. apache-tomcat-7.0.63-windows-x64
  3. Windows Server 2012 for both Web And Application Servers.

Tomcat Server.xml AJP Settings:

<!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />  

Error.log:

[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 (*)

Rewrite.log

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]

Access.log

10.16.1.3 - - [14/Aug/2015:18:27:07 +0200] "GET /app/launch.jsp HTTP/1.1" 503 323 0

Can somebody please help me with this as I am running out of time for this implementation and I have looked quite a lot on Web for a similar sort of issue but I am unable to find any solution.

Thanks a lot in Advance.

0

The error was due to the fact that AJP port for tomcat was not accessible from outside.

After opening the port, I simply placed the static content on the server on which Apache was hosting so I did not need to have a network path be mapped on the WebServer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.