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

Reply via email to