Hi.

First, respond only to the list, do not copy people extra.
I get every message to the list anyway, and if you copy me I get an extra copy which I do not need.

Second, on this list, it is preferred to send responses in the text of the original message, not on top. See : http://tomcat.apache.org/lists.html - tomcat users - Important - item #6.

Tapajyoti Roybarman wrote:
Hi Andre,

Thanks a lot for the quick response.

In my httpd.conf file I have added the below settings.

ProxyPass / http://localhost:8080/

This is what causes all requests to be forwarded to Tomcat.

ProxyPassReverse / http://localhost:8080/

This can stay as it is, it plays a role only for "redirect" responses from 
Tomcat.


This is to connect Apache Webserver and Tomcat. In future I would add more clusters and then modify the httpd.conf file accordingly.

Now because of this setting everything is being redirected to Tomcat. Even the static files are displayed from my application stack inside Tomcat Webapps.

Now, if I want to just do the opposite (from what you suggested) and add exceptions for files like jpg, png, css etc in my httpd.conf file, how do I do that?
Hope I was able to make my question clear.

Yes.

Maybe the first question would be : why do you want to serve these files from Apache httpd, instead of letting Tomcat do it ?
Do you /need/ an Apache httpd front-end for any other reason than to serve 
these files ?
Tomcat itself can perfectly well be configured to answer on port 80 like any normal webserver, and is quite efficient at serving static content such as these files.
So why complicate your life ?

But if you do have a valid reason to have a front-end Apache httpd (one of those would be if you need to run non-Java cgi-bin scripts or such things; another one would be to use httpd as a load-balancer also), then :

There are a multitude of possibilities, and I cannot go through all of them here (also considering that this is a Tomcat list, not a httpd list).

a) For simple cases, you may want to look at this :
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassmatch
In other words, replace the line
ProxyPass / http://localhost:8080/
by something more like :
ProxyPassMatch ^/.*\.(gif|jpg|css|...)$ ! http://localhost:8080/

Be careful of the remark on the same page about "Ordering ProxyPass Directives".

Also check if it is not easier to use
ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1
(if all you want to proxy to Tomcat are calls to JSP pages)

b) for more complex cases, you will need to use the mod_rewrite module, as it says in the above page.
See : http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
and siblings.

You can also use <Location> and <LocationMatch> sections in Apache httpd, and put your ProxyPass directives inside of these sections.

Which is the best way ? It depends...


> Where in my Apache2.2 folder structure do I keep the static
> contents?

Apache httpd expects the requested resources to be located somewhere below the directory named in the "DocumentRoot" directive of your configuration.
So for example :
- if "DocumentRoot" was "/var/www/myhost/docs/"
- and you currently have an image at 
(tomcat_base)/webapps/yourapp/images/image.jpg
(served for the request URL http://localhost:8080/yourapp/images/image.jpg)
you would need to move it to a directory :
/var/www/myhost/docs/yourapp/images/image.jpg
in order for it to be served by Apache for the request URL : http://localhost/yourapp/images/image.jpg)

That is because, once Apache has decided that it will not forward this request to Tomcat, it will then interpret the request URL according to its own rules.

(Note : you can modify this smartly with other RewriteRule's, but that is an exercise for level-2 httpd gurus)


And /do not/ set DocumentRoot to (tomcat_base)/webapps or anything like that, because that would create a big security hole.
(read : http://tomcat.apache.org/connectors-doc/reference/apache.html)
Keep the Apache DocumentRoot and the Tomcat webapps directories well-separated, unless and until you know exactly what you are doing, and unless you are prepared to explain this in detail to whoever will maintain that website after you.

Note also that mod_proxy_http is not the only way available to connect Apache httpd and Tomcat. There are also mod_proxy_ajp and mod_jk, each one of them with its own advantages and inconvenients compared to mod_proxy_http.


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

Reply via email to