Andre,

Thank you for your detailed description!
It cleared up a lot.

Just let me ask one more question.

A simple proxy_pass results in the following mapping (correct?)

http://hostname:8080/tom/app
  |   proxy_pass to
  |   127.0.0.1:8080/tom/app
  |
(tomcat_dir)/webapps/tom/app


Is there a way to eliminate the '/tom' part as follows?
('eliminate' : make it transparent from Tomcat side)

http://hostname:8080/tom/app
  |   proxy_pass
  |
  |   127.0.0.1:8080/tom/app
  |
  |   Tomcat mapping
(tomcat_dir)/webapps/app


A rewrite in the proxy_pass can remove '/tom',
however links *served* by Tomcat will not have '/tom'.
(-> no proxy -> not found error)

"When the application on the backend returns content including self-referential URLs using its own backend address and port, the client will usually not be able to use these URLs."
( http://tomcat.apache.org/connectors-doc/generic_howto/proxy.html )

The site above mentions Apache modul 'mod_jk' as a solution.
But my server is nginx, and google gives me approaches
with proxy_pass. Which would be fine IF  mappers on Tomcat side
would/could handle such prefixes.

If not, I guess I can hard-code the prefix into my apps (brrr),
or set up a   nginx --> Apache (mod_jk) --> Tomcat     redirect.
Or?

I am sorry about the 'trivial' label if it was offending.
I am new to Tomcat, chances are my questions seem trivial or nonsense...










On 2011-01-06 21:43, André Warnier wrote:
Gabor Pinter wrote:
Dear list,

I have a very trivial problem.

My setup:
CentOS 5.5
nginx 0.8.53
Tomcat6

net ---> nginx:80 (proxy_pass) ---> tomcat:8080

Proxy redirect is triggered by prefix "/tom/"

myhost:80/tom/<url> ---> 127.0.0.1:8080/tom/<url>

Now here is my question.
How can I let Tomcat know about this "/tom/" prefix?

<Host name="localhost/tom" ... seems to work in a somewhat confusing
manner

The Tomcat welcome page ignores prefix /tom/ in links
(hence, no pix + links are wrong ).
However, in apps (e.g. 'manager', 'examples') links are prefixed by
/tom/ (so pix & links are fine).


What is the authentic way to make the prefix absolutely transparent?


Hi.

It is not a trivial problem.
But I think that you are taking this from the wrong perspective.
You should not need to do anything special in Tomcat (or nginx) to let
Tomcat know about the /tom/ prefix. It already knows.
In particular, you should not do

<Host name="localhost/tom" ...

Leave it as it is

<Host name="localhost" ... >

because this has nothing to do with the directories or URLs that Tomcat
recognises.
(That's probably why it is "unpredictable").


Let'start from the beginning.

In a webserver like Tomcat, or Apache or nginx, there is a notion of
"URL space".

That is to say, when you have a URL like http://hostname/a/b/c.html, and
you consider the part after the protocol and hostname (thus here, the
/a/b/c.html part), you imagine a certain hierarchical sructure so that
/b is one of the things "below" /a, and /c.html is one of the things
"below" /a/b.

This webserver runs on a physcial host, and to store the physical
resource corresponding to /c.html above, it has a filesystem, where this
file actually lives.
For example, the above file c.html may in reality be on the disk, in a
directory like
/srv/www/host1/docs/a/b/c.html.

Ok so far ?

Now, between the "URL space", and the filesystem on disk, there is a
certain "mapping" taking place, so that the webserver would know that
when it receives request for the URL "/a/b/c.html", it should look for
that file in the directory "/srv/www/host1/docs/a/b/".
That mapping is done for example under Apache by the configuration line:

DocumentRoot /srv/www/host1/docs

In other words, this tells Apache that a URL = "/" refers to the disk
directory /srv/www/host1/docs/, and that a URL like "/a" refers to the
disk directory /srv/www/host1/docs/a/, and so on.

The same kind of mapping occurs in Tomcat, except that in Tomcat it is
not a

DocumentRoot /xxx

which tells Tomcat how to map URLs to the filesystem.
It is the "appBase" attribute in the <Host> tag, like :

<Host name="localhost" ... appBase="webapps" ..>

This "webapps" above tells Tomcat that a URL like
"http://hostname:8080/a/b/c.html";, should be mapped to

(tomcat_directory)/webapps/a/b/c.html

The only thing a bit special with Tomcat is respect of this mapping, is
that for Tomcat, the URL "/" is not mapped directly to

(tomcat_directory)/webapps/

Instead, it is mapped to

(tomcat_directory)/webapps/ROOT/

This "ROOT" name is special, and represents for Tomcat its "default
application".
In other words, for the URL : http://hostname:8080/a.html, Tomcat will
return the file
(tomcat_dir)/webapps/ROOT/a.html

Now, to get back to your initial question :

If in nginx, you are telling nginx to pass the following URLs to Tomcat :

myhost:80/tom/<url> ---> 127.0.0.1:8080/tom/<url>

then for a URL like :

http://myhost:80/tom/something.html,

nginx will forward it to Tomcat, and Tomcat will be looking for the file

(tomcat_dir)/webapps/tom/something.html

Automatically. Without having to do anything special in Tomcat.









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



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

Reply via email to