Re: adding a global URI prefix for Tomcat web apps
Hi, Thanks a million for guiding me through these hoops, and your patience with my confused anxiety to get this sorted out. It now works (of course) with these settings, and allows for a quite nice compromise. I'll briefly summarize problem and solution, if it can help others. The starting point was that I needed to reverse proxy Tomcat webapps behind Apache, with the Tomcat running on a non-public port. Additionally, some Tomcat apps need access to the host name of the original request, in order to generate working links. In order to avoid the problem that the proxied Tomcat doesn't 'see' the 'proxy' prefix of the original request, I decided to mirror that prefix for my Tomcat apps as well, and settle for following Apache proxy configuration: ProxyPreserveHoston ProxyPass/apps/ http://localhost:8082/apps/ ProxyPassReverse/apps/ http://mydomain/apps/ (note: the proxy domain in the second argument of ProxyPassReverse makes sure that location headers for redirects by the Tomcat apps are rewritten correctly by mod_proxy). Therefore, the Tomcat apps must be made accessible at e.g. http://localhost:8082/apps/my_app/, with the /app/ prefix before the actual name of the web app. This can be done easily by renaming the physical folder or WAR filename containing the web app, by adding the prefix, followed by a hash character (#) before the actual name of the application, e.g.: F:\tomcatApps\apps#my_app. This works well, except for Cocoon-based web apps, which choke on the hash in the filename. Hence, for those apps, following configuration provides a workaround: 1. move the folder or WAR file containing the web app outside of the host's appBase path, e.g.: F:\cocoonApps\my_app 2. add a file ${catalina.base}\conf\Catalina\[host name]\[prefix]#[app name].xml, e.g.: ${catalina.base}\conf\Catalina\localhost\apps#my_app.xml, with following content: Context docBase=F:/cocoonApps/my_app/ No further modifications of ${catalina.base}\conf\server.xml are needed. Again, thanks for the great help! Ron
Re: adding a global URI prefix for Tomcat web apps
2012/4/17 ron.vandenbranden@home ron.vandenbran...@kantl.be: So far, so good. Yet, I am struggling with the Tomcat side of this approach: finding a way to add a global path prefix for requests to Tomcat apps. The closest I got was this: 1. don't touch the physical location of the Tomcat apps: leave them at ${CATALINA.HOME}/webapps 2. change ${CATALINA.HOME}/conf/server.xml as follows: Host name=localhost appBase=webapps unpackWARs=true autoDeploy=false deployOnStartup=false Context path=/apps/my_app docBase=/my_app/ reloadable=true/ /Host I would not comment on the Apache HTTP server configuration. Just on the quoted part above. You have not told us what Tomcat version you are using, but in current Tomcat 6 and 7 you can add apps# prefix to the subdirectory and war file names in webapps directory and it will add apps/ to their URL, e.g.: mv webapps/my_app webapps/apps#my_app A war file name would be apps#my_app.war See Context page in Configuration Reference Guide for more details. Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: adding a global URI prefix for Tomcat web apps
On 17/04/2012 13:25, ron.vandenbranden@home wrote: Hi, I am setting up a reverse proxy configuration where all requests whose path starts with '/apps/' should be proxied by Apache to Tomcat. This IMO has 2 benefits: it makes it possible to reserve proxying to only the '/apps/' part of the URI space, and to use only a single proxy rule for all Tomcat apps (i.e. requests for any Tomcat app should just start with '/apps/'). For example, requests for http://mydomain/apps/my_app/ should be proxied to http://localhost:8082/my_app/. Note the absence of the '/apps/' prefix in the Tomcat URI: 'my_app' lives in the regular location at ${CATALINA_HOME}/webapps/my_app. I have achieved this using following Proxy rules in an Apache vhost.conf file: ProxyPreserveHoston ProxyPass/apps/http://localhost:8082/ ProxyPassReverse/apps/http://mydomain/ From the docs: ProxyPass/mirror/foo/ http://backend.example.com/ ProxyPassReverse /mirror/foo/ http://backend.example.com/ http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse ProxyPassReverse is designed to be used to address the situation you describe, you just appear to be using it incorrectly. Can you try again, with the correct 2nd parameter for this directive? p (Note: I have used ProxyPreserveHost since my Tomcat app needs access to the original host to generate further links). All goes well, except for absolute links that are generated by one part of my Tomcat app. Given above configuration, my Tomcat app will 'see' this request: http://mydomain/my_app, and hence generate links without the '/apps/' prefix that should trigger proxying for those links. It took me some time, but I understand now that this is essential characteristic of proxying, and that there's no 'standard' way to pass on that '/apps/' prefix of the original request to the proxied app. Hence, I started to investigate another possibility, namely defining a global prefix for all Tomcat apps, and proxy the Tomcat apps with following settings: ProxyPreserveHoston ProxyPass/apps/http://localhost:8082/apps/ ProxyPassReverse/apps/http://mydomain/apps/ This would proxy requests for http://mydomain/apps/my_app/ to http://localhost:8082/apps/my_app/. Since all apps on the Tomcat server will be accessed behind a proxy, I have no problem that this '/apps/' prefix will be required for all Tomcat apps. So far, so good. Yet, I am struggling with the Tomcat side of this approach: finding a way to add a global path prefix for requests to Tomcat apps. The closest I got was this: 1. don't touch the physical location of the Tomcat apps: leave them at ${CATALINA.HOME}/webapps 2. change ${CATALINA.HOME}/conf/server.xml as follows: Host name=localhost appBase=webapps unpackWARs=true autoDeploy=false deployOnStartup=false Context path=/apps/my_app docBase=/my_app/ reloadable=true/ /Host While this makes the my_app Tomcat app accessible at http://localhost:8082/apps/my_app/, it also suggests that all Tomcat apps should be defined manually in a separate Context element. This makes it less flexible to add new Tomcat web apps (and would actually mean more configuration work than declaring separate proxy rules for each app in the Apache configuration, without the '/apps/' prefix). I tried this: Context path=/apps docBase=/ reloadable=true/ (and @docBase variants such as , or .), but this doesn't work: no indication of any webapps being deployed in the Tomcat console output, and all requests return a 404 error. Hence my question: is there a simple(r) way of 'declaring' a global URI prefix for Tomcat webapps? Any advice much appreciated! Ron - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org -- [key:62590808] signature.asc Description: OpenPGP digital signature
Re: adding a global URI prefix for Tomcat web apps
Hi Pid, Thanks for your suggestion. On 17/04/2012 21:16, Pid wrote: From the docs: ProxyPass/mirror/foo/ http://backend.example.com/ ProxyPassReverse /mirror/foo/ http://backend.example.com/ http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse ProxyPassReverse is designed to be used to address the situation you describe, you just appear to be using it incorrectly. I think your ProxyPassReverse setting only works with ProxyPreserveHost switched off: in that case, the my_app Tomcat app, when proxied via http://mydomain/apps/my_app/ will 'see' (and generate) links like http://localhost:8082/my_app/. This will only work if Tomcat is running on a public port; not when it is hidden behind a firewall. That's why I arrived at using ProxyPreserveHost. In order to make this work, the ProxyPassReverse setting must refer to the public URL (see advice at https://www.indexis.be/indexWeb/index.jsp?language=nlp=oeandis=y). Following settings do work, mostly: On 17/04/2012 13:25, ron.vandenbranden@home wrote: ProxyPreserveHoston ProxyPass/apps/http://localhost:8082/ ProxyPassReverse/apps/http://mydomain/ Yet, here too, all the my_app Tomcat app sees from the request is http://mydomain/my_app/, since the '/app/' part has been filtered out after the proxy handling. Consequently, those links won't work. That's why I tried if I could add '/app/' as a global path prefix to Tomcat apps. Kind regards, Ron - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: adding a global URI prefix for Tomcat web apps
On Apr 18, 2012 12:43 AM, ron.vandenbranden@home ron.vandenbran...@kantl.be wrote: Hi Pid, Thanks for your suggestion. On 17/04/2012 21:16, Pid wrote: From the docs: ProxyPass/mirror/foo/ http://backend.example.com/ ProxyPassReverse /mirror/foo/ http://backend.example.com/ http://httpd.apache.org/docs/**2.2/mod/mod_proxy.html#**proxypassreversehttp://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse ProxyPassReverse is designed to be used to address the situation you describe, you just appear to be using it incorrectly. I think your ProxyPassReverse setting only works with ProxyPreserveHost switched off: in that case, the my_app Tomcat app, when proxied via http://mydomain/apps/my_app/ will 'see' (and generate) links like http://localhost:8082/my_app/. This will only work if Tomcat is running on a public port; not when it is hidden behind a firewall. That's why I arrived at using ProxyPreserveHost. In order to make this work, the ProxyPassReverse setting must refer to the public URL (see advice at https://www.indexis.be/**indexWeb/index.jsp?language=**nlp=oeandis=yhttps://www.indexis.be/indexWeb/index.jsp?language=nlp=oeandis=y). Following settings do work, mostly: On 17/04/2012 13:25, ron.vandenbranden@home wrote: ProxyPreserveHoston ProxyPass/apps/http://localhost:8082/ ProxyPassReverse/apps/http://mydomain/ Yet, here too, all the my_app Tomcat app sees from the request is http://mydomain/my_app/, since the '/app/' part has been filtered out after the proxy handling. Consequently, those links won't work. That's why I tried if I could add '/app/' as a global path prefix to Tomcat apps. Kind regards, Ron --**--**- To unsubscribe, e-mail: users-unsubscribe@tomcat.**apache.orgusers-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: adding a global URI prefix for Tomcat web apps
Hi Konstantin, Many thanks for your excellent suggestion. Sorry, I forgot to mention that I'm running Tomcat-7.0.27, so that should work. On 17/04/2012 17:27, Konstantin Kolinko wrote: I would not comment on the Apache HTTP server configuration. Just on the quoted part above. You have not told us what Tomcat version you are using, but in current Tomcat 6 and 7 you can add apps# prefix to the subdirectory and war file names in webapps directory and it will add apps/ to their URL, e.g.: mv webapps/my_app webapps/apps#my_app A war file name would be apps#my_app.war See Context page in Configuration Reference Guide for more details. Nice! In my tests this works for some web apps, but apparently, some (using cocoon-2.1.11) have problems. Any request for cococoon-2.1.11-based web apps return errors about files that are not found. For example, suppose my app is located at F:\tomcat\webapps\apps#my_app, requests for http://localhost:8080/apps/my_app/ return errors such as: Message: F:\tomcat\webapps\stylesheets\system\exception2html.xslt (The system cannot find the path specified) Description: org.apache.cocoon.ProcessingException: Unable to get transformer handler for file:///F:/tomcat/webapps/stylesheets/system/exception2html.xslt atmap:serialize - file:///F:/tomcat/webapps/apps#my_app/sitemap.xmap:922:53 atmap:transform - file:///F:/tomcat/webapps/apps#my_app/sitemap.xmap:917:79 atmap:generate type=exception - file:///F:/tomcat/webapps/apps#my_app/sitemap.xmap:916:51 Sender: org.apache.cocoon.servlet.CocoonServlet Source: Cocoon Servlet cause java.io.FileNotFoundException: F:\tomcat\webapps\stylesheets\system\exception2html.xslt (The system cannot find the path specified) Does this imply that this 'hash' prefix is still experimental, depending on the web app? Best regards, Ron - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: adding a global URI prefix for Tomcat web apps
2012/4/18 ron.vandenbranden@home ron.vandenbran...@kantl.be: Hi Konstantin, Many thanks for your excellent suggestion. Sorry, I forgot to mention that I'm running Tomcat-7.0.27, so that should work. On 17/04/2012 17:27, Konstantin Kolinko wrote: I would not comment on the Apache HTTP server configuration. Just on the quoted part above. You have not told us what Tomcat version you are using, but in current Tomcat 6 and 7 you can add apps# prefix to the subdirectory and war file names in webapps directory and it will add apps/ to their URL, e.g.: mv webapps/my_app webapps/apps#my_app A war file name would be apps#my_app.war See Context page in Configuration Reference Guide for more details. Nice! In my tests this works for some web apps, but apparently, some (using cocoon-2.1.11) have problems. Any request for cococoon-2.1.11-based web apps return errors about files that are not found. For example, suppose my app is located at F:\tomcat\webapps\apps#my_app, requests for http://localhost:8080/apps/my_app/ return errors such as: Message: F:\tomcat\webapps\stylesheets\system\exception2html.xslt (The system cannot find the path specified) Description: org.apache.cocoon.ProcessingException: Unable to get transformer handler for file:///F:/tomcat/webapps/stylesheets/system/exception2html.xslt atmap:serialize - file:///F:/tomcat/webapps/apps#my_app/sitemap.xmap:922:53 atmap:transform - file:///F:/tomcat/webapps/apps#my_app/sitemap.xmap:917:79 atmap:generate type=exception - file:///F:/tomcat/webapps/apps#my_app/sitemap.xmap:916:51 Sender: org.apache.cocoon.servlet.CocoonServlet Source: Cocoon Servlet cause java.io.FileNotFoundException: F:\tomcat\webapps\stylesheets\system\exception2html.xslt (The system cannot find the path specified) Does this imply that this 'hash' prefix is still experimental, depending on the web app? No. It is Cocoon that is broken. There is File - URL conversion somewhere that does not encode characters properly, and '#' should be %-encoded if it is in an URL. Last time it was discussed on this list was several years ago. Either it is a rare use case, or it is just already fixed. http://tomcat.markmail.org/thread/5ixxlkiyfsou63vh http://tomcat.markmail.org/thread/ygac3etewhtpmf2p http://tomcat.markmail.org/message/oolap6mmrs22f5wr Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: adding a global URI prefix for Tomcat web apps
Hi, On 17/04/2012 22:49, Konstantin Kolinko wrote: No. It is Cocoon that is broken. There is File - URL conversion somewhere that does not encode characters properly, and '#' should be %-encoded if it is in an URL. Last time it was discussed on this list was several years ago. Either it is a rare use case, or it is just already fixed. http://tomcat.markmail.org/thread/5ixxlkiyfsou63vh http://tomcat.markmail.org/thread/ygac3etewhtpmf2p http://tomcat.markmail.org/message/oolap6mmrs22f5wr Ouch, that's really bad. Apparently it isn't fixed yet :-(. Thanks for the pointers, anyway. I thought of a last option: -leave the Tomcat webapps as is (without an 'apps#' prefix in the folder names) -configure Apache to proxy all requests ProxyPreserveHoston ProxyPass/ http://localhost:8082/ ProxyPassReverse / http://mydomain/ -add proxy exceptions for all other paths: ProxyPass /noproxy ! I haven't tested this, but I guess this won't solve the problem with the '/apps/' prefix (which is necessary for our URL scheme design). So, it seems (due to the Cocoon bug) the approach I described in my original message is the only one that will work consistently: -define a prefix for proxied requests in Apache -define all Tomcat apps with that prefix literally in distinct Context containers Kind regards, Ron -- Ron Van den Branden Wetenschappelijk attaché / Senior Researcher Reviews Editor LLC. The Journal of Digital Scholarship in the Humanities Centrum voor Teksteditie en Bronnenstudie - CTB (KANTL) Centre for Scholarly Editing and Document Studies Koninklijke Academie voor Nederlandse Taal- en Letterkunde Royal Academy of Dutch Language and Literature Koningstraat 18 / b-9000 Gent / Belgium tel: +32 9 265 93 51 / fax: +32 9 265 93 49 E-mail : ron.vandenbran...@kantl.be http://www.kantl.be/ctb
Re: adding a global URI prefix for Tomcat web apps
2012/4/17 ron.vandenbranden@home ron.vandenbran...@kantl.be: 2. change ${CATALINA.HOME}/conf/server.xml as follows: Host name=localhost appBase=webapps unpackWARs=true autoDeploy=false deployOnStartup=false Context path=/apps/my_app docBase=/my_app/ reloadable=true/ /Host More comment on the above, as you have already read the docs. Putting Context element into server.xml is considered a bad practice. Instead of that you'd put it into separate XML file, conf/Catalina/localhost/apps#my_app.xml as Context docBase=/docbase/of/my_app/ / That reloadable=true is not really needed. Your docbase can be anywhere (outside of webapps directory) and need not have the '#' sign in it. The working folder for your app will still be ${catalina.base}/Catalina/localhost/apps#myapp with a hash char in it, but I think that will work with Cocoon. BTW, I wonder how Cocoon behaves if your application is in a war file and you run with Host unpackWARs=false / Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: adding a global URI prefix for Tomcat web apps
Hi, Sorry if I'm being a bit dense, but could I check if I'm understanding correctly? I can't get it working with your suggestions. On 18/04/2012 0:04, Konstantin Kolinko wrote: 2012/4/17 ron.vandenbranden@homeron.vandenbran...@kantl.be: 2. change ${CATALINA.HOME}/conf/server.xml as follows: Host name=localhost appBase=webapps unpackWARs=true autoDeploy=false deployOnStartup=false Context path=/apps/my_app docBase=/my_app/ reloadable=true/ /Host More comment on the above, as you have already read the docs. PuttingContext element into server.xml is considered a bad practice. Instead of that you'd put it into separate XML file, conf/Catalina/localhost/apps#my_app.xml as Context docBase=/docbase/of/my_app/ / That reloadable=true is not really needed. Your docbase can be anywhere (outside of webapps directory) and need not have the '#' sign in it. The working folder for your app will still be ${catalina.base}/Catalina/localhost/apps#myapp with a hash char in it, but I think that will work with Cocoon. I have my webapps located at F:\tomcatApps (so outside of the catalina tree), where 'my_app' lives in a folder named 'apps#my_app'. So I'm specifying this in ${catalina.base}/conf/server.xml: Host name=localhost appBase=F:/tomcatApps unpackWARs=true autoDeploy=false deployOnStartup=false ...without any further Context elements. Next, I create following file at ${catalina.base}/conf/Catalina/localhost/apps#my_app: Context docBase=/my_app/ / (as I understand from the docs that the @docbase value must be relative to the Host's @appBase). When I start Tomcat with these settings, no webapps are deployed at all. I tried toggling the values for @autoDeploy and @deployOnStartup, and only the latter seems to make any webapps to be deployed. Yet, the Tomcat console window then logs following message: INFO: Deploying configuration descriptor F:\tomcat-7.0.27\conf\Catalina\localhost\apps#my_app 18-apr-2012 0:37:56 org.apache.catalina.startup.HostConfig deployDescriptor WARNING: A docBase F:\tomcatApps\my_app inside the Host appBase has been specified, and will be ignored Eventually, the 'my_app' app is deployed, but with the same result: Cocoon chokes on the hash in the folder name. BTW, I wonder how Cocoon behaves if your application is in a war file and you run withHost unpackWARs=false / Hmm, I could give that a try (tomorrow, perhaps, off to bed now), though I recall some issues with Cocoon-based web apps that needed a physical directory structure. Again, many thanks for your help! Kind regards, Ron - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: adding a global URI prefix for Tomcat web apps
From: ron.vandenbranden@home [mailto:ron.vandenbran...@kantl.be] Subject: Re: adding a global URI prefix for Tomcat web apps I have my webapps located at F:\tomcatApps (so outside of the catalina tree), where 'my_app' lives in a folder named 'apps#my_app'. So I'm specifying this in ${catalina.base}/conf/server.xml: Host name=localhost appBase=F:/tomcatApps unpackWARs=true autoDeploy=false deployOnStartup=false But now they're _inside_ Tomcat's space, since you specified an appBase pointing to them. Put appBase back to what it was. Note that Konstantin did not tell you to change that. Next, I create following file at ${catalina.base}/conf/Catalina/localhost/apps#my_app: Context docBase=/my_app/ / (as I understand from the docs that the @docbase value must be relative to the Host's @appBase). Not when you specify a leading slash. However, you need to place these apps _outside_ of the Host appBase, not inside it, and you should specify the complete (absolute) path to the webapp. (The webapp must be outside of appBase in order to make the # trick work and not confuse Cocoon.) - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: adding a global URI prefix for Tomcat web apps
2012/4/18 ron.vandenbranden@home ron.vandenbran...@kantl.be: Hi, Sorry if I'm being a bit dense, but could I check if I'm understanding correctly? I can't get it working with your suggestions. On 18/04/2012 0:04, Konstantin Kolinko wrote: 2012/4/17 ron.vandenbranden@homeron.vandenbran...@kantl.be: 2. change ${CATALINA.HOME}/conf/server.xml as follows: Host name=localhost appBase=webapps unpackWARs=true autoDeploy=false deployOnStartup=false Context path=/apps/my_app docBase=/my_app/ reloadable=true/ /Host More comment on the above, as you have already read the docs. PuttingContext element into server.xml is considered a bad practice. Instead of that you'd put it into separate XML file, conf/Catalina/localhost/apps#my_app.xml as Context docBase=/docbase/of/my_app/ / That reloadable=true is not really needed. Your docbase can be anywhere (outside of webapps directory) and need not have the '#' sign in it. The working folder for your app will still be ${catalina.base}/Catalina/localhost/apps#myapp with a hash char in it, but I think that will work with Cocoon. I have my webapps located at F:\tomcatApps (so outside of the catalina tree), where 'my_app' lives in a folder named 'apps#my_app'. 1. Rename the folder to my_app. So it is F:\tomcatApps\my_app So I'm specifying this in ${catalina.base}/conf/server.xml: Host name=localhost appBase=F:/tomcatApps unpackWARs=true autoDeploy=false deployOnStartup=false 2. It should be appBase=webapps, like Chuck noted! 3. deployOnStartup=true, like you already figured it. ...without any further Context elements. Next, I create following file at ${catalina.base}/conf/Catalina/localhost/apps#my_app: Correct place, the name: apps#my_app.xml (you omitted .xml extension in your mail, but it seems it was just a typo) Context docBase=/my_app/ / Context docBase=F:\tomcatApps\my_app / (as I understand from the docs that the @docbase value must be relative to the Host's @appBase). When I start Tomcat with these settings, no webapps are deployed at all. I tried toggling the values for @autoDeploy and @deployOnStartup, and only the latter seems to make any webapps to be deployed. Yet, the Tomcat console window then logs following message: INFO: Deploying configuration descriptor F:\tomcat-7.0.27\conf\Catalina\localhost\apps#my_app 18-apr-2012 0:37:56 org.apache.catalina.startup.HostConfig deployDescriptor WARNING: A docBase F:\tomcatApps\my_app inside the Host appBase has been specified, and will be ignored Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org