Author |
|
jfha73
Joined: 18 Aug 2011 Posts: 62 Location: New York
|
Posted: Wed 15 Feb '17 21:52 Post subject: Proxypass question |
|
|
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: 152 Location: Schömberg, Baden-Württemberg, Germany
|
Posted: Thu 16 Feb '17 22:56 Post subject: |
|
|
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
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 ).
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.
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 |
|
Back to top |
|
TPL
Joined: 25 Mar 2014 Posts: 24 Location: Germany, Hamburg
|
Posted: Fri 17 Feb '17 10:10 Post subject: |
|
|
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: 152 Location: Schömberg, Baden-Württemberg, Germany
|
Posted: Fri 17 Feb '17 15:25 Post subject: |
|
|
@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
|
Posted: Tue 21 Feb '17 14:12 Post subject: |
|
|
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
|
Posted: Tue 21 Feb '17 14:39 Post subject: Here is the error from mod_jk |
|
|
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 |
|