You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Marc Chamberlin <ma...@marcchamberlin.com> on 2016/10/17 17:16:48 UTC

Apache mod_jk connector question about alias

Hello -  My apologies if this has already been asked or the wrong mail 
list, but Google is not coming up with an answer for me, so here goes...

I am trying to set up the mod_jk connector between an Apache HTTPD 
server and Tomcat with the intent of supporting virtual hosts, and 
serving static content from the Apache server and forwarding jsp and 
servlet requests to Tomcat. Typical scenario I know...

Most of this I have working but the trouble I am having is with the use 
an Alias directive for the Apache server. Following instructions for the 
JSP examples that came with my distribution for Tomcat 8, I created a 
configuration for

>  <IfModule mod_jk.c>
>
>   # The following line makes apache aware of the location of
>   # the /jsp-examples context
>   Alias /jsp-examples "/srv/tomcat/webapps/examples/jsp"
>
>   <Directory "/srv/tomcat/webapps/examples/jsp">
>         Options Indexes  FollowSymLinks
>         AllowOverride None
>     # Controls who can get stuff from this server.
>     <IfModule !mod_access_compat.c>
>             Require all granted
>     </IfModule>
>     <IfModule mod_access_compat.c>
>         Order allow,deny
>         Allow from all
>     </IfModule>
>   </Directory>
>
>   # Mounted stuff goes via tomcat (ajp13)
>   JkMount /jsp-examples tomcatWorker1
>   JkMount /jsp-examples/* tomcatWorker1
>   # Serve html, css, js, jpg, png and gif using Apache
>   JkUnMount /*.html tomcatWorker1
>   JkUnMount /*.css tomcatWorker1
>   JkUnMount /*.js tomcatWorker1
>   JkUnMount /*.jpg  tomcatWorker1
>   JkUnMount /*.png  tomcatWorker1
>   JkUnMount /*.gif  tomcatWorker1
> </IfModule>

I am actually defining this in the context of a virtual host and if 
necessary I can post its configuration as well.

Using the JK debug level and monitoring the mod_jk.log file I can see 
what is going wrong, I just don't know how to rectify it -

> [Mon Oct 17 09:28:01.145 2016] [30237:139868423546816] [debug] 
> ajp_connection_tcp_send_message::jk_ajp_common.c (1208): sending to 
> ajp13 pos=4 len=469 max=8192
> [Mon Oct 17 09:28:01.145 2016] [30237:139868423546816] [debug] 
> ajp_connection_tcp_send_message::jk_ajp_common.c (1208): 0000 12 34 01 
> D1 02 02 00 08 48 54 54 50 2F 31 2E 31  - .4......HTTP/1.1
> [Mon Oct 17 09:28:01.145 2016] [30237:139868423546816] [debug] 
> ajp_connection_tcp_send_message::jk_ajp_common.c (1208): 0010 00 00 0E 
> 2F 6A 73 70 2D 65 78 61 6D 70 6C 65 73  - .../jsp-examples
> [Mon Oct 17 09:28:01.145 2016] [30237:139868423546816] [debug] 
> ajp_connection_tcp_send_message::jk_ajp_common.c (1208): 0020 2F 00 00 
> 0D 31 39 32 2E 31 36 38 2E 31 30 2E 31  - /...192.168.10.1

This excerpt shows that the Apache server is sending a message to the 
Tomcat worker telling it to find a resource "/jsp-examples" which of 
course doesn't really exist and so Tomcat reports a "Not Found" failure. 
What I want is for the Apache server to send the actual location that 
this alias is mapped to i.e. "/examples/jsp", which is what actually 
exists in the Tomcat context. I can fool Tomcat into handling this alias 
request by creating a link named jsp-examples -> examples/jsp within the 
Tomcat webapps directory but that seems like a hack and not something I 
want to have to do/maintain for all the other resources I will want to 
handle via alias commands.

Is there a magic incantation that I am missing?  Thanks in advance for 
suggestions/help....     Marc...



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache mod_jk connector question about alias

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 20.10.2016 18:23, Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Marc,
>
> On 10/20/16 11:34 AM, Marc Chamberlin wrote:
>> On 10/20/2016 3:19 AM, Andr� Warnier (tomcat) wrote:
>>> On 20.10.2016 01:58, Christopher Schultz wrote:
>>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
>>>>
>>>> Marc,
>>>>
>>>> On 10/18/16 7:59 PM, Marc Chamberlin wrote:
>>>>> On 10/17/2016 10:36 AM, Rainer Jung wrote:
>>>>>>
>>>>>> Alias maps URIs to local file system directories. JkMount
>>>>>> maps URIs to remote back end requests.
>>>>>>
>>>>>> You can not change JkMount forwarding using Alias (except
>>>>>> that if you have a comflict between Alias and JkMount only
>>>>>> one of them wins).
>>>>>>
>>>>>> As far as I understand you are not really trying to map
>>>>>> requests to the local web server file system, but instead
>>>>>> want to forward to a Tomcat back end but change the URI
>>>>>> path which is used when accessing Apache to something else
>>>>>> being used to acces Tomcat. E.g. the URI
>>>>>> /jsp-examples/something gets used when accessing Apache and
>>>>>> mod_jk should send this request as /examples/jsp/something
>>>>>> to the Tomcat back end.
>>>>>>
>>>>>> If you really need to change URIs, then often mod_proxy is
>>>>>> much easier to set up, because it has specific directives
>>>>>> for this (ProxyPass etc.).
>>>>>>
>>>>>> With mod_jk you would first need to use mod_rewrite
>>>>>> RewriteRules to change the URI, and then JkMount to forward
>>>>>> them. More details can be found at
>>>>>>
>>>>>> http://tomcat.apache.org/connectors-doc/common_howto/proxy.html#UR
> L%2
>>>>
>>>>>>
> 0Rewriting
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>> The rest of this docs page might be useful as well.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Rainer
>>>>>>
>>>>> Thanks a million Rainer, you got me over that hump! I have
>>>>> it working now but have another question - When the response
>>>>> is generated for a request, that used the alias in the URL,
>>>>> is there a way to keep the client browser from displaying
>>>>> what the alias got mapped to?
>>>>>
>>>>> So for example, if I use the alias in the URL -
>>>>> http://www.mydomain.com/jsp-examples  that I send to the
>>>>> Apache server, and it in turn forwards that request to Tomcat
>>>>> as http://www.mydomain.com/examples/jsp, I would prefer that
>>>>> the response, sent back to the user, contains the original,
>>>>> aliased or unaliased, version of the URL that he/she typed,
>>>>> and not just the resolved version. As it stands I am always
>>>>> getting the response URL of
>>>>> http://www.mydomain.com/examples/jsp displayed in the client
>>>>> browser.
>>>>>
>>>>> What follows is my current version of the config file that I
>>>>> am using for the jsp-examples. Seems to be working mostly OK,
>>>>> so hopefully I am on the right track. FYI - I intend to
>>>>> include these config files in various virtual hosts
>>>>> configurations each of which have their own document root,
>>>>> hence the reason for the Alias commands at the beginning of
>>>>> this config file.
>>>>>
>>>>> Thanks again in advance for any and all offers of help,
>>>>> thoughts, and replies...
>>>>
>>>> Your best bet is to name the context in Tomcat to be whatever
>>>> you really want the URL path to be. This will remove all kinds
>>>> of problems you are likely to see in the future because of your
>>>> decision to try to rewrite URLs.
>>>>
>>>> I never understand why people would rather spend a great deal
>>>> of time configuring around the fact that this simple command
>>>> will get everything working without any other issues:
>>>>
>>>> $ mv webapps/name-you-have webapps/name-you-want
>>>>
>>> +10 Because once you start playing with Aliases and RewriteRules,
>>> you are setting yourself up for a lot of future additional
>>> complications in terms of Redirects, Authentication, etc.. most
>>> of which you cannot even imagine right now.
>>>
>> Thanks Christopher, Andre for your comments and I will certainly
>> take them under consideration. If I were working in a simple
>> environment where all I had to do was to focus on Tomcat and Apache
>> I would certainly agree with you. Your simplistic solution of
>> renaming directories would indeed be the correct choice.
>>
>> The problem is, is that the real world is not quite so
>> accommodating. I am trying to support a team of users who are using
>> other third party applications and also using cross-sectional tools
>> that require multiple resources/directories in the Tomcat/Apache
>> web directories, that all need to be coordinated. Some of this can
>> be solved with directory renaming or links, but in some cases it
>> becomes a question of whether the dog is wagging the tail or the
>> tail is wagging the dog in terms of the amount of work involved to
>> solve a problem; such as a simple Tomcat/Apache alone related
>> answer (directory renaming) implies. So I am exploring the choices
>> I have within the Tomcat/Apache tool space in order to determine
>> what choice is best. If indeed the tools available within Tomcat
>> and Apache are so odious to use, then yes I will also have to
>> explore the option of changing other tools, software, and
>> configurations in order to accommodate Tomcat and Apache.
>
> It's not a question of whether of not the tools are odious, it's the
> fact that a highly-complicated environment is going to require
> highly-complicated configuration. I'm suggesting that you simplify
> things. You will quickly find that you will need to start re-writing
> entire pages of content to fix-up link URLs and stuff like that.
> mod_proxy will only auto-rewrite headers such as Location (for
> redirects) and Set-Cookie; it will not fix all of the links that the
> web application produces.
>
> At the point that you start re-writing entire pages of content as they
> traverse your reverse-proxy is when you know you are really fighting
> against a Better Way of doing things.
>
> Are you suggesting that your environment is so complex that it is not
> possible to change the name of a single file/directory (possibly
> amongst a cluster of servers, of course)? The alternative is miles of
> configuration that probably will always have some kind of problem with
> it because you have missed an edge case.
>
>> My understanding of Tomcat and Apache is that they are supposedly
>> robust enterprise grade tools, designed to work in complex
>> environments. So my hope is that issues like this have been already
>> addressed with elegant solutions. ;-)
>
> The elegant solution is to re-name your application to the
> context-path you want to use, rather than using a mountain of band-aids.
>
> This is not a problem unique to Tomcat and/or Apache httpd. You'll
> find this same problem with every other reverse proxy / servlet
> container combination that I know of.
>
>> FYI I am using the jsp and servlet examples here as just a simple
>> model of what I want to accomplish. I could really care less about
>> those particular web applications.
>
> Understood.
>

I can only agree with Christopher.
The tools available in Apache httpd and Apache Tomcat are plentiful, powerful, flexible, 
and allow basically any mangling that you might think of in terms of URLs and what actual 
resource they point to.
The problem is all the other bits, such as what Christopher mentions about the 
applications creating pages with embedded links to further resources. And the problem is 
also in how the browser, in receiving such pages, will interpret these links (relative or 
absolute).  There exist tools in Apache httpd and Tomcat to handle this too (think "output 
filters"), but the point is that once you start with this, you don't really know where it 
will end.
And even more so, if you do not know the applications in detail, and/or you have no 
possibility to influence how they are written.
(Think e.g. of links in pages such as : <img src="../images/logo.gif"> and what the 
browser would make of it).



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache mod_jk connector question about alias

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Marc,

On 10/20/16 11:34 AM, Marc Chamberlin wrote:
> On 10/20/2016 3:19 AM, Andr� Warnier (tomcat) wrote:
>> On 20.10.2016 01:58, Christopher Schultz wrote:
>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
>>> 
>>> Marc,
>>> 
>>> On 10/18/16 7:59 PM, Marc Chamberlin wrote:
>>>> On 10/17/2016 10:36 AM, Rainer Jung wrote:
>>>>> 
>>>>> Alias maps URIs to local file system directories. JkMount
>>>>> maps URIs to remote back end requests.
>>>>> 
>>>>> You can not change JkMount forwarding using Alias (except
>>>>> that if you have a comflict between Alias and JkMount only
>>>>> one of them wins).
>>>>> 
>>>>> As far as I understand you are not really trying to map
>>>>> requests to the local web server file system, but instead
>>>>> want to forward to a Tomcat back end but change the URI
>>>>> path which is used when accessing Apache to something else
>>>>> being used to acces Tomcat. E.g. the URI
>>>>> /jsp-examples/something gets used when accessing Apache and
>>>>> mod_jk should send this request as /examples/jsp/something
>>>>> to the Tomcat back end.
>>>>> 
>>>>> If you really need to change URIs, then often mod_proxy is
>>>>> much easier to set up, because it has specific directives
>>>>> for this (ProxyPass etc.).
>>>>> 
>>>>> With mod_jk you would first need to use mod_rewrite
>>>>> RewriteRules to change the URI, and then JkMount to forward
>>>>> them. More details can be found at
>>>>> 
>>>>> http://tomcat.apache.org/connectors-doc/common_howto/proxy.html#UR
L%2
>>>
>>>>> 
0Rewriting
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>> The rest of this docs page might be useful as well.
>>>>> 
>>>>> Regards,
>>>>> 
>>>>> Rainer
>>>>> 
>>>> Thanks a million Rainer, you got me over that hump! I have
>>>> it working now but have another question - When the response
>>>> is generated for a request, that used the alias in the URL,
>>>> is there a way to keep the client browser from displaying
>>>> what the alias got mapped to?
>>>> 
>>>> So for example, if I use the alias in the URL - 
>>>> http://www.mydomain.com/jsp-examples  that I send to the
>>>> Apache server, and it in turn forwards that request to Tomcat
>>>> as http://www.mydomain.com/examples/jsp, I would prefer that
>>>> the response, sent back to the user, contains the original,
>>>> aliased or unaliased, version of the URL that he/she typed,
>>>> and not just the resolved version. As it stands I am always
>>>> getting the response URL of
>>>> http://www.mydomain.com/examples/jsp displayed in the client 
>>>> browser.
>>>> 
>>>> What follows is my current version of the config file that I
>>>> am using for the jsp-examples. Seems to be working mostly OK,
>>>> so hopefully I am on the right track. FYI - I intend to
>>>> include these config files in various virtual hosts
>>>> configurations each of which have their own document root,
>>>> hence the reason for the Alias commands at the beginning of
>>>> this config file.
>>>> 
>>>> Thanks again in advance for any and all offers of help,
>>>> thoughts, and replies...
>>> 
>>> Your best bet is to name the context in Tomcat to be whatever
>>> you really want the URL path to be. This will remove all kinds
>>> of problems you are likely to see in the future because of your
>>> decision to try to rewrite URLs.
>>> 
>>> I never understand why people would rather spend a great deal
>>> of time configuring around the fact that this simple command
>>> will get everything working without any other issues:
>>> 
>>> $ mv webapps/name-you-have webapps/name-you-want
>>> 
>> +10 Because once you start playing with Aliases and RewriteRules,
>> you are setting yourself up for a lot of future additional
>> complications in terms of Redirects, Authentication, etc.. most
>> of which you cannot even imagine right now.
>> 
> Thanks Christopher, Andre for your comments and I will certainly
> take them under consideration. If I were working in a simple
> environment where all I had to do was to focus on Tomcat and Apache
> I would certainly agree with you. Your simplistic solution of
> renaming directories would indeed be the correct choice.
> 
> The problem is, is that the real world is not quite so
> accommodating. I am trying to support a team of users who are using
> other third party applications and also using cross-sectional tools
> that require multiple resources/directories in the Tomcat/Apache
> web directories, that all need to be coordinated. Some of this can
> be solved with directory renaming or links, but in some cases it
> becomes a question of whether the dog is wagging the tail or the
> tail is wagging the dog in terms of the amount of work involved to
> solve a problem; such as a simple Tomcat/Apache alone related
> answer (directory renaming) implies. So I am exploring the choices
> I have within the Tomcat/Apache tool space in order to determine
> what choice is best. If indeed the tools available within Tomcat
> and Apache are so odious to use, then yes I will also have to
> explore the option of changing other tools, software, and 
> configurations in order to accommodate Tomcat and Apache.

It's not a question of whether of not the tools are odious, it's the
fact that a highly-complicated environment is going to require
highly-complicated configuration. I'm suggesting that you simplify
things. You will quickly find that you will need to start re-writing
entire pages of content to fix-up link URLs and stuff like that.
mod_proxy will only auto-rewrite headers such as Location (for
redirects) and Set-Cookie; it will not fix all of the links that the
web application produces.

At the point that you start re-writing entire pages of content as they
traverse your reverse-proxy is when you know you are really fighting
against a Better Way of doing things.

Are you suggesting that your environment is so complex that it is not
possible to change the name of a single file/directory (possibly
amongst a cluster of servers, of course)? The alternative is miles of
configuration that probably will always have some kind of problem with
it because you have missed an edge case.

> My understanding of Tomcat and Apache is that they are supposedly
> robust enterprise grade tools, designed to work in complex
> environments. So my hope is that issues like this have been already
> addressed with elegant solutions. ;-)

The elegant solution is to re-name your application to the
context-path you want to use, rather than using a mountain of band-aids.

This is not a problem unique to Tomcat and/or Apache httpd. You'll
find this same problem with every other reverse proxy / servlet
container combination that I know of.

> FYI I am using the jsp and servlet examples here as just a simple
> model of what I want to accomplish. I could really care less about
> those particular web applications.

Understood.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJYCO97AAoJEBzwKT+lPKRYspcP/j58DLdp/kELZYOhY80mqhb4
POyuogOBb/sUmpMES3PBbctx/CaPoFo4p8DO3Z2kRc5z13lpznfIMs32vDadPFrf
6STMzOQY8FnxC6o8Rf/wBxRCtk4OI0u359o2+y0nbmc7iOHoaLXUx9Ms/WzlNz6z
UNxBrJh1c3e5qSsdnJMOKAWnUv0jNqT1dol9jqLjtgzUtGKVcayPTObQxajAPMcf
H13qrk722obLwRPhTdV/Gm9JrzJ0Vw167zfirDT754rLYpTs2DNgw2Zl76TQiVut
R4RRZD2Wn+1pfYakhSGDN5cECuirXXKIHPHcZmpLsfneuoXw7AWgnlLBSjRLLKp9
/WTmzYVme5Le9I5+mK6qT0xI7kJ+SDAIDLI2WwKbyZzhEG51tMe5NkWNmwwsGTZ6
5bOWNz2ROx8l4qIlmHT0EGmftM+bXs+xNtUxMkeZHYmolvkv/9D5fyDOoO4zI8CS
C2YJy13VPmu31Dqa8cOyVyCJw6J3ZUiO/Dyh0dqmkFMMsJfxyCuRwYG2uDzovBdw
dDh5+EVYhhYXqCkzV3S5bzrClbsXgZIYNrWwau3oOm/QelbYoqQ6ul9JPuCQ7dA7
NopwZDOYEE0TaGRP8riNw8ziN5d1X2zGEdoNnXuSte8MLylu8FFctgtBGQoVjhZi
/PqoEOUCUv583Qbob5v0
=QGpl
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache mod_jk connector question about alias

Posted by Marc Chamberlin <ma...@marcchamberlin.com>.
On 10/20/2016 3:19 AM, Andr� Warnier (tomcat) wrote:
> On 20.10.2016 01:58, Christopher Schultz wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA256
>>
>> Marc,
>>
>> On 10/18/16 7:59 PM, Marc Chamberlin wrote:
>>> On 10/17/2016 10:36 AM, Rainer Jung wrote:
>>>>
>>>> Alias maps URIs to local file system directories. JkMount maps
>>>> URIs to remote back end requests.
>>>>
>>>> You can not change JkMount forwarding using Alias (except that if
>>>> you have a comflict between Alias and JkMount only one of them
>>>> wins).
>>>>
>>>> As far as I understand you are not really trying to map requests
>>>> to the local web server file system, but instead want to forward
>>>> to a Tomcat back end but change the URI path which is used when
>>>> accessing Apache to something else being used to acces Tomcat.
>>>> E.g. the URI /jsp-examples/something gets used when accessing
>>>> Apache and mod_jk should send this request as
>>>> /examples/jsp/something to the Tomcat back end.
>>>>
>>>> If you really need to change URIs, then often mod_proxy is much
>>>> easier to set up, because it has specific directives for this
>>>> (ProxyPass etc.).
>>>>
>>>> With mod_jk you would first need to use mod_rewrite RewriteRules
>>>> to change the URI, and then JkMount to forward them. More details
>>>> can be found at
>>>>
>>>> http://tomcat.apache.org/connectors-doc/common_howto/proxy.html#URL%2
>> 0Rewriting
>>>>
>>>>
>>>>
>>>>
>> The rest of this docs page might be useful as well.
>>>>
>>>> Regards,
>>>>
>>>> Rainer
>>>>
>>> Thanks a million Rainer, you got me over that hump! I have it
>>> working now but have another question - When the response is
>>> generated for a request, that used the alias in the URL, is there a
>>> way to keep the client browser from displaying what the alias got
>>> mapped to?
>>>
>>> So for example, if I use the alias in the URL -
>>> http://www.mydomain.com/jsp-examples  that I send to the Apache
>>> server, and it in turn forwards that request to Tomcat as
>>> http://www.mydomain.com/examples/jsp, I would prefer that the
>>> response, sent back to the user, contains the original, aliased or
>>> unaliased, version of the URL that he/she typed, and not just the
>>> resolved version. As it stands I am always getting the response URL
>>> of http://www.mydomain.com/examples/jsp displayed in the client
>>> browser.
>>>
>>> What follows is my current version of the config file that I am
>>> using for the jsp-examples. Seems to be working mostly OK, so
>>> hopefully I am on the right track. FYI - I intend to include these
>>> config files in various virtual hosts configurations each of which
>>> have their own document root, hence the reason for the Alias
>>> commands at the beginning of this config file.
>>>
>>> Thanks again in advance for any and all offers of help, thoughts,
>>> and replies...
>>
>> Your best bet is to name the context in Tomcat to be whatever you
>> really want the URL path to be. This will remove all kinds of problems
>> you are likely to see in the future because of your decision to try to
>> rewrite URLs.
>>
>> I never understand why people would rather spend a great deal of time
>> configuring around the fact that this simple command will get
>> everything working without any other issues:
>>
>> $ mv webapps/name-you-have webapps/name-you-want
>>
> +10
> Because once you start playing with Aliases and RewriteRules, you are 
> setting yourself up for a lot of future additional complications in 
> terms of Redirects, Authentication, etc..
> most of which you cannot even imagine right now.
>
Thanks Christopher, Andre for your comments and I will certainly take 
them under consideration. If I were working in a simple environment 
where all I had to do was to focus on Tomcat and Apache I would 
certainly agree with you. Your simplistic solution of renaming 
directories would indeed be the correct choice.

The problem is, is that the real world is not quite so accommodating. I 
am trying to support a team of users who are using other third party 
applications and also using cross-sectional tools that require multiple 
resources/directories in the Tomcat/Apache web directories, that all 
need to be coordinated. Some of this can be solved with directory 
renaming or links, but in some cases it becomes a question of whether 
the dog is wagging the tail or the tail is wagging the dog in terms of 
the amount of work involved to solve a problem; such as a simple 
Tomcat/Apache alone related answer (directory renaming) implies. So I am 
exploring the choices I have within the Tomcat/Apache tool space in 
order to determine what choice is best. If indeed the tools available 
within Tomcat and Apache are so odious to use, then yes I will also have 
to explore the option of changing other tools, software, and 
configurations in order to accommodate Tomcat and Apache.

My understanding of Tomcat and Apache is that they are supposedly robust 
enterprise grade tools, designed to work in complex environments. So my 
hope is that issues like this have been already addressed with elegant 
solutions. ;-) FYI I am using the jsp and servlet examples here as just 
a simple model of what I want to accomplish. I could really care less 
about those particular web applications.

      Marc...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
"The Truth is out there" - Spooky


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache mod_jk connector question about alias

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 20.10.2016 01:58, Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Marc,
>
> On 10/18/16 7:59 PM, Marc Chamberlin wrote:
>> On 10/17/2016 10:36 AM, Rainer Jung wrote:
>>>
>>> Alias maps URIs to local file system directories. JkMount maps
>>> URIs to remote back end requests.
>>>
>>> You can not change JkMount forwarding using Alias (except that if
>>> you have a comflict between Alias and JkMount only one of them
>>> wins).
>>>
>>> As far as I understand you are not really trying to map requests
>>> to the local web server file system, but instead want to forward
>>> to a Tomcat back end but change the URI path which is used when
>>> accessing Apache to something else being used to acces Tomcat.
>>> E.g. the URI /jsp-examples/something gets used when accessing
>>> Apache and mod_jk should send this request as
>>> /examples/jsp/something to the Tomcat back end.
>>>
>>> If you really need to change URIs, then often mod_proxy is much
>>> easier to set up, because it has specific directives for this
>>> (ProxyPass etc.).
>>>
>>> With mod_jk you would first need to use mod_rewrite RewriteRules
>>> to change the URI, and then JkMount to forward them. More details
>>> can be found at
>>>
>>> http://tomcat.apache.org/connectors-doc/common_howto/proxy.html#URL%2
> 0Rewriting
>>>
>>>
>>>
>>>
> The rest of this docs page might be useful as well.
>>>
>>> Regards,
>>>
>>> Rainer
>>>
>> Thanks a million Rainer, you got me over that hump! I have it
>> working now but have another question - When the response is
>> generated for a request, that used the alias in the URL, is there a
>> way to keep the client browser from displaying what the alias got
>> mapped to?
>>
>> So for example, if I use the alias in the URL -
>> http://www.mydomain.com/jsp-examples  that I send to the Apache
>> server, and it in turn forwards that request to Tomcat as
>> http://www.mydomain.com/examples/jsp, I would prefer that the
>> response, sent back to the user, contains the original, aliased or
>> unaliased, version of the URL that he/she typed, and not just the
>> resolved version. As it stands I am always getting the response URL
>> of http://www.mydomain.com/examples/jsp displayed in the client
>> browser.
>>
>> What follows is my current version of the config file that I am
>> using for the jsp-examples. Seems to be working mostly OK, so
>> hopefully I am on the right track. FYI - I intend to include these
>> config files in various virtual hosts configurations each of which
>> have their own document root, hence the reason for the Alias
>> commands at the beginning of this config file.
>>
>> Thanks again in advance for any and all offers of help, thoughts,
>> and replies...
>
> Your best bet is to name the context in Tomcat to be whatever you
> really want the URL path to be. This will remove all kinds of problems
> you are likely to see in the future because of your decision to try to
> rewrite URLs.
>
> I never understand why people would rather spend a great deal of time
> configuring around the fact that this simple command will get
> everything working without any other issues:
>
> $ mv webapps/name-you-have webapps/name-you-want
>
+10
Because once you start playing with Aliases and RewriteRules, you are setting yourself up 
for a lot of future additional complications in terms of Redirects, Authentication, etc..
most of which you cannot even imagine right now.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache mod_jk connector question about alias

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Marc,

On 10/18/16 7:59 PM, Marc Chamberlin wrote:
> On 10/17/2016 10:36 AM, Rainer Jung wrote:
>> 
>> Alias maps URIs to local file system directories. JkMount maps
>> URIs to remote back end requests.
>> 
>> You can not change JkMount forwarding using Alias (except that if
>> you have a comflict between Alias and JkMount only one of them
>> wins).
>> 
>> As far as I understand you are not really trying to map requests
>> to the local web server file system, but instead want to forward
>> to a Tomcat back end but change the URI path which is used when
>> accessing Apache to something else being used to acces Tomcat.
>> E.g. the URI /jsp-examples/something gets used when accessing
>> Apache and mod_jk should send this request as
>> /examples/jsp/something to the Tomcat back end.
>> 
>> If you really need to change URIs, then often mod_proxy is much
>> easier to set up, because it has specific directives for this
>> (ProxyPass etc.).
>> 
>> With mod_jk you would first need to use mod_rewrite RewriteRules
>> to change the URI, and then JkMount to forward them. More details
>> can be found at
>> 
>> http://tomcat.apache.org/connectors-doc/common_howto/proxy.html#URL%2
0Rewriting
>>
>>
>>
>> 
The rest of this docs page might be useful as well.
>> 
>> Regards,
>> 
>> Rainer
>> 
> Thanks a million Rainer, you got me over that hump! I have it
> working now but have another question - When the response is
> generated for a request, that used the alias in the URL, is there a
> way to keep the client browser from displaying what the alias got
> mapped to?
> 
> So for example, if I use the alias in the URL - 
> http://www.mydomain.com/jsp-examples  that I send to the Apache
> server, and it in turn forwards that request to Tomcat as 
> http://www.mydomain.com/examples/jsp, I would prefer that the
> response, sent back to the user, contains the original, aliased or
> unaliased, version of the URL that he/she typed, and not just the
> resolved version. As it stands I am always getting the response URL
> of http://www.mydomain.com/examples/jsp displayed in the client
> browser.
> 
> What follows is my current version of the config file that I am
> using for the jsp-examples. Seems to be working mostly OK, so
> hopefully I am on the right track. FYI - I intend to include these
> config files in various virtual hosts configurations each of which
> have their own document root, hence the reason for the Alias
> commands at the beginning of this config file.
> 
> Thanks again in advance for any and all offers of help, thoughts,
> and replies...

Your best bet is to name the context in Tomcat to be whatever you
really want the URL path to be. This will remove all kinds of problems
you are likely to see in the future because of your decision to try to
rewrite URLs.

I never understand why people would rather spend a great deal of time
configuring around the fact that this simple command will get
everything working without any other issues:

$ mv webapps/name-you-have webapps/name-you-want

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJYCAivAAoJEBzwKT+lPKRYANAP/Rh2kvvCHDkVam0HOPky9az3
J9KfYb8JVw/G65iNbyYH+PYBpetYragZAKXm8TqID3H5o95yGCFU4A0TduoqVA2R
hqmkM6vXbLclsENL44lJDPiYR7EhO8CwoDe764YzXvB7OMzGSwlNG4jI6SmBHxNO
SdvFE8G6bYAGj5zqA+hATMNHv/VhY2esgHbx4rV46hmDouh23yyUVZiu6LEFg0LQ
ThDgZzhvURRrb9xv4J78Ml0PMcD/v3F7cYJvlZwU2boLoD9c8p+nTgX+7tN4TZ9d
fYsOAuLLWfxQUj/WddN9JjosdkEmf8bdXivBH5JCe5RYeSO1BgVqhxi4PEIp5tUs
zTDN5Xb7g+9pnz8Lo5bDYwzNU+BYqtOSI+HdKC8x2Pu+rGGde3q040QEIJIPInaD
Ef0Fr8OInhC4z3MnI3dtS8iB6q8k5wwAk9l+2Nt3Up6oAlPUG/jT3xY66oFnr7wS
Q1w/M6uwRrmeU/7jjmIOfI+pcgYhOkj2+iRbyBkXvcOazmHDJz3mMx2wdEHSqTE6
5VHW5zqcgOZCTasXQ648KWW/0ajsQvAaU5rMjqJdTHrlpHlWeD2cyPxE1MeOxBq/
PBkuA2rCTwew9P8yeFyiInJtf5l17jbB+IlpaNzEr/ukDob+2BhqmKdUWlCACLp7
iZiAhqne7jaNJEwZL0zp
=z2Vs
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache mod_jk connector question about alias

Posted by Marc Chamberlin <ma...@marcchamberlin.com>.
On 10/17/2016 10:36 AM, Rainer Jung wrote:
>
> Alias maps URIs to local file system directories.
> JkMount maps URIs to remote back end requests.
>
> You can not change JkMount forwarding using Alias (except that if you 
> have a comflict between Alias and JkMount only one of them wins).
>
> As far as I understand you are not really trying to map requests to 
> the local web server file system, but instead want to forward to a 
> Tomcat back end but change the URI path which is used when accessing 
> Apache to something else being used to acces Tomcat. E.g. the URI 
> /jsp-examples/something gets used when accessing Apache and mod_jk 
> should send this request as /examples/jsp/something to the Tomcat back 
> end.
>
> If you really need to change URIs, then often mod_proxy is much easier 
> to set up, because it has specific directives for this (ProxyPass etc.).
>
> With mod_jk you would first need to use mod_rewrite RewriteRules to 
> change the URI, and then JkMount to forward them. More details can be 
> found at
>
> http://tomcat.apache.org/connectors-doc/common_howto/proxy.html#URL%20Rewriting 
>
>
> The rest of this docs page might be useful as well.
>
> Regards,
>
> Rainer
>
Thanks a million Rainer, you got me over that hump! I have it working 
now but have another question - When the response is generated for a 
request, that used the alias in the URL, is there a way to keep the 
client browser from displaying what the alias got mapped to?

So for example, if I use the alias in the URL - 
http://www.mydomain.com/jsp-examples  that I send to the Apache server, 
and it in turn forwards that request to Tomcat as 
http://www.mydomain.com/examples/jsp, I would prefer that the response, 
sent back to the user, contains the original, aliased or unaliased, 
version of the URL that he/she typed, and not just the resolved version. 
As it stands I am always getting the response URL of 
http://www.mydomain.com/examples/jsp displayed in the client browser.

What follows is my current version of the config file that I am using 
for the jsp-examples. Seems to be working mostly OK, so hopefully I am 
on the right track.
FYI - I intend to include these config files in various virtual hosts 
configurations each of which have their own document root, hence the 
reason for the Alias commands at the beginning of this config file.

Thanks again in advance for any and all offers of help, thoughts, and 
replies...

      Marc..

>   # The following line makes apache aware of the location of
>   # the /jsp-examples context
>   Alias /examples/jsp "/srv/tomcat/webapps/examples/jsp"
>   Alias /jsp-examples "/srv/tomcat/webapps/examples/jsp"
>
>   <Directory "/srv/tomcat/webapps/examples/jsp">
>         Options Indexes  FollowSymLinks
>         AllowOverride None
>     # Controls who can get stuff from this server.
>     <IfModule !mod_access_compat.c>
>             Require all granted
>     </IfModule>
>     <IfModule mod_access_compat.c>
>         Order allow,deny
>         Allow from all
>     </IfModule>
>   </Directory>
>
>   <Directory "/srv/tomcat/webapps/examples/jsp/WEB-INF/">
>     # AllowOverride None
>     <IfModule !mod_access_compat.c>
>             Require all denied
>     </IfModule>
>     <IfModule mod_access_compat.c>
>         deny from all
>     </IfModule>
>   </Directory>
>
>   <IfModule mod_rewrite.c>
>          RewriteEngine On
>          RewriteRule "^/jsp-examples" "/examples/jsp" [PT]
>   </IfModule>
>
>   <IfModule mod_jk.c>
>         # Mounted stuff goes via tomcat (ajp13)
>         #  JkMount /jsp-examples tomcatWorker1
>         #  JkMount /jsp-examples/* tomcatWorker1
>         JkMount /examples/jsp tomcatWorker1
>         JkMount /examples/jsp/* tomcatWorker1
>         # Serve html, css, js, jpg, png and gif using Apache
>         JkUnMount /*.html tomcatWorker1
>         JkUnMount /*.css tomcatWorker1
>         JkUnMount /*.js tomcatWorker1
>         JkUnMount /*.jpg  tomcatWorker1
>         JkUnMount /*.png  tomcatWorker1
>         JkUnMount /*.gif  tomcatWorker1
>   </IfModule>

-- 
"The Truth is out there" - Spooky


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Apache mod_jk connector question about alias

Posted by Rainer Jung <ra...@kippdata.de>.
Am 17.10.2016 um 19:16 schrieb Marc Chamberlin:
> Hello -  My apologies if this has already been asked or the wrong mail
> list, but Google is not coming up with an answer for me, so here goes...
>
> I am trying to set up the mod_jk connector between an Apache HTTPD
> server and Tomcat with the intent of supporting virtual hosts, and
> serving static content from the Apache server and forwarding jsp and
> servlet requests to Tomcat. Typical scenario I know...
>
> Most of this I have working but the trouble I am having is with the use
> an Alias directive for the Apache server. Following instructions for the
> JSP examples that came with my distribution for Tomcat 8, I created a
> configuration for
>
>>  <IfModule mod_jk.c>
>>
>>   # The following line makes apache aware of the location of
>>   # the /jsp-examples context
>>   Alias /jsp-examples "/srv/tomcat/webapps/examples/jsp"
>>
>>   <Directory "/srv/tomcat/webapps/examples/jsp">
>>         Options Indexes  FollowSymLinks
>>         AllowOverride None
>>     # Controls who can get stuff from this server.
>>     <IfModule !mod_access_compat.c>
>>             Require all granted
>>     </IfModule>
>>     <IfModule mod_access_compat.c>
>>         Order allow,deny
>>         Allow from all
>>     </IfModule>
>>   </Directory>
>>
>>   # Mounted stuff goes via tomcat (ajp13)
>>   JkMount /jsp-examples tomcatWorker1
>>   JkMount /jsp-examples/* tomcatWorker1
>>   # Serve html, css, js, jpg, png and gif using Apache
>>   JkUnMount /*.html tomcatWorker1
>>   JkUnMount /*.css tomcatWorker1
>>   JkUnMount /*.js tomcatWorker1
>>   JkUnMount /*.jpg  tomcatWorker1
>>   JkUnMount /*.png  tomcatWorker1
>>   JkUnMount /*.gif  tomcatWorker1
>> </IfModule>
>
> I am actually defining this in the context of a virtual host and if
> necessary I can post its configuration as well.
>
> Using the JK debug level and monitoring the mod_jk.log file I can see
> what is going wrong, I just don't know how to rectify it -
>
>> [Mon Oct 17 09:28:01.145 2016] [30237:139868423546816] [debug]
>> ajp_connection_tcp_send_message::jk_ajp_common.c (1208): sending to
>> ajp13 pos=4 len=469 max=8192
>> [Mon Oct 17 09:28:01.145 2016] [30237:139868423546816] [debug]
>> ajp_connection_tcp_send_message::jk_ajp_common.c (1208): 0000 12 34 01
>> D1 02 02 00 08 48 54 54 50 2F 31 2E 31  - .4......HTTP/1.1
>> [Mon Oct 17 09:28:01.145 2016] [30237:139868423546816] [debug]
>> ajp_connection_tcp_send_message::jk_ajp_common.c (1208): 0010 00 00 0E
>> 2F 6A 73 70 2D 65 78 61 6D 70 6C 65 73  - .../jsp-examples
>> [Mon Oct 17 09:28:01.145 2016] [30237:139868423546816] [debug]
>> ajp_connection_tcp_send_message::jk_ajp_common.c (1208): 0020 2F 00 00
>> 0D 31 39 32 2E 31 36 38 2E 31 30 2E 31  - /...192.168.10.1
>
> This excerpt shows that the Apache server is sending a message to the
> Tomcat worker telling it to find a resource "/jsp-examples" which of
> course doesn't really exist and so Tomcat reports a "Not Found" failure.
> What I want is for the Apache server to send the actual location that
> this alias is mapped to i.e. "/examples/jsp", which is what actually
> exists in the Tomcat context. I can fool Tomcat into handling this alias
> request by creating a link named jsp-examples -> examples/jsp within the
> Tomcat webapps directory but that seems like a hack and not something I
> want to have to do/maintain for all the other resources I will want to
> handle via alias commands.
>
> Is there a magic incantation that I am missing?  Thanks in advance for
> suggestions/help....     Marc...

Alias maps URIs to local file system directories.
JkMount maps URIs to remote back end requests.

You can not change JkMount forwarding using Alias (except that if you 
have a comflict between Alias and JkMount only one of them wins).

As far as I understand you are not really trying to map requests to the 
local web server file system, but instead want to forward to a Tomcat 
back end but change the URI path which is used when accessing Apache to 
something else being used to acces Tomcat. E.g. the URI 
/jsp-examples/something gets used when accessing Apache and mod_jk 
should send this request as /examples/jsp/something to the Tomcat back end.

If you really need to change URIs, then often mod_proxy is much easier 
to set up, because it has specific directives for this (ProxyPass etc.).

With mod_jk you would first need to use mod_rewrite RewriteRules to 
change the URI, and then JkMount to forward them. More details can be 
found at

http://tomcat.apache.org/connectors-doc/common_howto/proxy.html#URL%20Rewriting

The rest of this docs page might be useful as well.

Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org