Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3C25310B5A for ; Thu, 5 Dec 2013 18:12:35 +0000 (UTC) Received: (qmail 58948 invoked by uid 500); 5 Dec 2013 18:12:31 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 58910 invoked by uid 500); 5 Dec 2013 18:12:31 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 58900 invoked by uid 99); 5 Dec 2013 18:12:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Dec 2013 18:12:31 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of aw@ice-sa.com designates 212.85.38.228 as permitted sender) Received: from [212.85.38.228] (HELO tor.combios.es) (212.85.38.228) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Dec 2013 18:12:24 +0000 Received: from [192.168.245.216] (montserrat.wissensbank.com [212.85.37.175]) (Authenticated sender: andre.warnier@ice-sa.com) by tor.combios.es (Postfix) with ESMTPA id 4A1A73C33D9 for ; Thu, 5 Dec 2013 19:12:28 +0100 (CET) Message-ID: <52A0C1EF.2040902@ice-sa.com> Date: Thu, 05 Dec 2013 19:11:59 +0100 From: =?ISO-8859-1?Q?Andr=E9_Warnier?= Reply-To: Tomcat Users List User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Need Information regarding Apache Webserver static file configuration References: <1386146601.45844.ezmlm@tomcat.apache.org> <529F2AD3.5030203@ice-sa.com> <529F3D72.1030508@ice-sa.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Tapajyoti Roybarman wrote: > Hi Andre, > > I apologize for not following the mailing rule. Actually this is the first > time that I am taking the help of such a forum. > > Before I begin asking you anything I want to thank you for such a detailed > explanation. > > To begin with, answer to your question - "why do you want to serve these > files from Apache httpd, instead of letting Tomcat do it?" I am planning > to use Apache httpd as a Load Balancer. And to improve the performance of > my application, I want to serve the static content from apache itself. > > Now, as per your suggestion I have modified the entries of httpd.conf file > to this. > > ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/ > ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1 > ProxyPassReverse / http://localhost:8080/ > > ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/ - By using > this setting I am able to serve static files from apache. I have kept my > files under DocumentRoot as per your suggestion. > > ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1 - If I am not using > this. I am getting a page not found error for my page Login.jsp present > inside Tomcat/Webapps/MyApplication. When I am using this setting I am > able to reach to the page Login.jsp. > > Now, the probelm is, the Login.jsp actually sends the request to a servlet > to complete the login functionality. I am not able to reach to that > servlet using the above settings. The URL is - > http://localhost/MyApplication/servlet/login > > What should I add in the httpd.conf to achieve this? Assuming that all the URLs which contain "/servlet/" are to be forwarded to Tomcat, you could use something like : ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/ ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1 ProxyPassMatch ^/(.*/servlet/.*)$ http://localhost:8080/$1 ProxyPassReverse / http://localhost:8080/ Note : still be careful of the order of the directives. As indicated in the corresponding mod_proxy documentation, httpd evaluates each Proxy* directive in turn, from top to bottom, and the first one that matches "wins the day". For example, if you had this order : ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1 ProxyPassMatch ^/(.*/servlet/.*)$ http://localhost:8080/$1 ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/ then a URL like http://localhost/MyApplication/servlet/something/image.jpg would be proxied to Tomcat, because the line ProxyPassMatch ^/(.*/servlet/.*)$ http://localhost:8080/$1 would match before the line ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/ As I recall, httpd has an internal flag that means "proxy this URL" or "don't proxy this URL". As soon as one of the expressions in a Proxy* statement matches, that flag is set (one way or the other), and no further evaluation of Proxy* statements takes place. That also means that if you happen to know that there are many more URLs containing "/servlet/" than there are ending in ".jsp", you could do some (very small) optimisation by doing this : ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/ ProxyPassMatch ^/(.*/servlet/.*)$ http://localhost:8080/$1 ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1 Alternatively again : if, once you have "filtered out" all URLs ending in (gif|jpg|css|png), you know that all the remaining ones that start with "/MyApplication" should be forwarded to Tomcat, then you could use : ProxyPassMatch ^/.*\.(gif|jpg|css|png)$ ! http://localhost:8080/ ProxyPassMatch ^/MyApplication http://localhost:8080/MyApplication and that would take care of both /MyApplication/servlet/login /MyApplication/Login.jsp and many others. It's fun playing with.. And mod_rewrite is even more fun. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org