logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Proxypass question
Author
jfha73



Joined: 18 Aug 2011
Posts: 62
Location: New York

PostPosted: Wed 15 Feb '17 21:52    Post subject: Proxypass question Reply with quote

Hey guys,

I have a server setup with Apache and Tomcat I setup apache to be a proxy of the Tomcat by adding this:

Code:
ProxyPass /tomcat http://localhost:8080/
ProxyPassReverse /tomcat http://localhost:8080/

ProxyPass /tomcat/docs http://localhost:8080/docs/
ProxyPassReverse /tomcat/docs http://localhost:8080/docs/

ProxyPass /tomcat/examples http://localhost:8080/examples/
ProxyPassReverse /tomcat/examples http://localhost:8080/examples/

ProxyPass /tomcat/manager http://localhost:8080/manager/
ProxyPassReverse /tomcat/manager http://localhost:8080/manager/

ProxyPass /tomcat/host-manager http://localhost:8080/host-manager/
ProxyPassReverse /tomcat/host-manager http://localhost:8080/host-manage


But only the first one works, the rest are redirecting to http://localhost/folder, it is not adding the tomcat before the folder, any idea why?

Thanks.
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 149
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Thu 16 Feb '17 22:56    Post subject: Reply with quote

Hello,

TL;DR
You only need the ProxyPass for /tomcat and not for every subdirectory.
Tomcat sends relative redirects (allowed according to RFC7231) but Apache does not rewrite them. It only rewrites absolute redirects (as requested in -obsolete- RFC2616)

Long version Rolling Eyes
I only used the following two lines in Apache's config as you don't need a ProxyPass for every subdirectory - it is already handled by the ProxyPass for the tomcat-directory:
Code:
ProxyPass /tomcat/ http://localhost:8080/
ProxyPassReverse /tomcat/ http://localhost:8080/

and could successfully access (192.168.0.12 is my Apache-Webserver)
Code:
http://192.168.0.12/tomcat/
http://192.168.0.12/tomcat/docs/
http://192.168.0.12/tomcat/examples/servlets/
http://192.168.0.12/tomcat/manager/html


But: according to RFC2616 (which is obsoleted by RFC7231 and others) redirects have to be absolute, according to RFC7231 they also could be relative (source: https://en.wikipedia.org/wiki/HTTP_location and of course the RFCs itself Very Happy).
When Tomcat sends redirects it sends them as relative redirects: when accessing http://<servername>:8080/tomcats/examples/servlets Tomcat sends a redirect to /examples/servlets/ (with trailing /) but Apache seems not to rewrite this redirect to a /tomcat/examples/servlets/ before passing it to my browser.
This means that I finally made the same observation as you. Very Happy

I also checked this with two php-scripts on another webserer (192.168.0.4 in this case) sending redirects and the following two lines in the 192.168.0.12's Apache-config:
Code:
ProxyPass /atom/ http://192.168.0.4/
ProxyPassReverse /atom/ http://192.168.0.4/

documentation1.php
Code:
<?php
  header("Location: http" . (((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"]=="on"))?"s":"") . "://" . $_SERVER['HTTP_HOST'] . "/dokumentation/");
?>

documentation2.php
Code:
<?php
  header("Location: /dokumentation/");
?>


When accessing http://192.168.0.12/atom/dokumentation1.php the scripts sends a redirect to http://192.168.0.4/dokumentation/ which is rewritten by mod_proxy to http://192.168.0.12/atom/dokumentation/ before sending it to my browser.
When accessing http://192.168.0.12/atom/dokumentation2.php the scripts sends a redirect to /dokumentation/ which is not rewritten by mod_proxy and simply passed to by browser so I end up on http://192.168.0.12/dokumentation/

Maybe someone with programming-knowledge about mod_proxy can verify this (Apache's mod_proxy does not rewrite relative redirects) in the sourcecode Question
Back to top
TPL



Joined: 25 Mar 2014
Posts: 24
Location: Germany, Hamburg

PostPosted: Fri 17 Feb '17 10:10    Post subject: Reply with quote

Hello,

in my opinion the best way is mod_jk. Maybe you can try it.

workers.properties
Code:
worker.list=worker01
worker.worker01.type=ajp13
worker.worker01.host=127.0.0.1
worker.worker01.port=8009


http configuration
Code:
JkMount /manager|/* worker01
JkMount /docs|/* worker01



http://tomcat.apache.org/connectors-doc/common_howto/quick.html
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 149
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Fri 17 Feb '17 15:25    Post subject: Reply with quote

@TPL: you are absolutely right - mod_jk is better than mod_proxy for connecting to a tomcat-backend.

But the problem with the relative redirects is not limited to tomcat (as shown with the PHP-example).

Maybe someone knows a solution/fix for this?
Back to top
jfha73



Joined: 18 Aug 2011
Posts: 62
Location: New York

PostPosted: Tue 21 Feb '17 14:12    Post subject: Reply with quote

Proxypass is not working for me when I put just 1 entry, I have mod_jk, but no matter how I configure it nothing shows up, I always get a 404 Not found with mod_jk.
Back to top
jfha73



Joined: 18 Aug 2011
Posts: 62
Location: New York

PostPosted: Tue 21 Feb '17 14:39    Post subject: Here is the error from mod_jk Reply with quote

I think this is why mod_jk is showing me not found everywhere:

Code:
[Tue Feb 21 07:37:09.449 2017] [25670:140213915813760] [error] extension_fix::jk_uri_worker_map.c (580): Could not find worker with name 'worker1' in uri map post processing.
[Tue Feb 21 07:37:09.449 2017] [25670:140213915813760] [error] extension_fix::jk_uri_worker_map.c (580): Could not find worker with name 'worker1' in uri map post processing.


The module is not finding the workers.
Back to top


Reply to topic   Topic: Proxypass question View previous topic :: View next topic
Post new topic   Forum Index -> Apache