0

I'm trying to implement the scheme Browser Client -> Apache2 Proxy -> Tomcat Application Server. Apache2 and Tomcat on separate servers. But the proxy does not work as I expected. Apache2 virtual host setting:

  <VirtualHost *:80 *:443>
    ServerName example.com
    ServerAlias www.example.com

    ProxyPass /MyApp http://tomcatdomain.com/MyApp
    ProxyPassReverse /MyApp tomcatdomain.com/MyApp
  </VirtualHost>

if I make a request to open the page in the browser, http://example.com/MyApp, the application opens correctly, but the URL is different - http://tomcatdomain.com/MyApp. Next, I look at the Ajax request and see that it does not work according to the scheme I expected:

 12:35:20.537 GET https://example.com/MyApp/service/test [HTTP/1.1 302  41ms]
 12:35:20.617 GET https://tomcatdomain.com/MyApp/service/test

Expected: [request] client->apache2->tomcat [response] tomcat->apache2->client

Actually: [request] client->apache2 [response] apache2->client [request2] client ->tomcat [response2] tomcat -> client

My first question is how to make the client receive a response from the tomkat with one query?

The next problem with the ProxyPreserveHost parameter - I need to keep the original url(example.com) when opening the application (not tomcatdomain.com). I append ProxyPreserveHost to the appache2 setting:

<VirtualHost *:80 *:443>
    ServerName example.com
    ServerAlias www.example.com

    ProxyPreserveHost On

    ProxyPass /MyApp http://tomcatdomain.com/MyApp
    ProxyPassReverse /MyApp tomcatdomain.com/MyApp
</VirtualHost>

I also prepared the tomkat server.xml:

   <Host name="example.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Alias>www.example.com</Alias>
    <Context path="" docBase="MyApp"/>
   </Host>

I make a request and what I see in the browser:

The page isn’t redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

I make AJAX request and I see 22 identical requests that are not answered:

 12:54:48.020 GET https://example.com/MyApp/service/test [HTTP/1.1 302  28ms]
 12:54:48.042 GET https://example.com/MyApp/service/test [HTTP/1.1 302  4ms]
 ... 22 requests!
 12:54:48.367 GET https://example.com/MyApp/service/test [HTTP/1.1 302  3ms]

I conclude that the request is not redirected to the tomcat server.

To confirm my guesses, I corrected the Apache2 settings:

  <VirtualHost *:80 *:443>
    ServerName example.com
    ServerAlias www.example.com

    ProxyPreserveHost On

    ProxyPass /MyApp http://tomcatdomain.com/MyApp**ABCD**
    ProxyPassReverse /MyApp tomcatdomain.com/MyApp**ABCD**
  </VirtualHost>

And in browser I see: Not Found The requested URL /MyAppABCD was not found on this server. Apache/2.4.27 (Ubuntu) Server at example.com Port 80

Apache2 searches for URL mapping not on tomcat, but on the same apache2?

Tell me, please, how to implement the scheme, when the browser open the page, the data will be received from Tomcat via Apache2 proxy, and the original URL will be saved? Thanks.

0

The problem was with the self-signed certificates on the Apache2 and Tomcat. It was necessary to make a cross-certification. If you remove the encryption(SSL or TLS) between Apache2 and Tomcat (NOT! WWW and Apache2), then no additional settings are required.

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.