aspose file tools*
The moose likes Tomcat and the fly likes ProxyPass from httpd to tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "ProxyPass from httpd to tomcat" Watch "ProxyPass from httpd to tomcat" New topic
Author

ProxyPass from httpd to tomcat

Sub Gowda
Greenhorn

Joined: Sep 23, 2012
Posts: 10
Hi,

I am not sure if this is the correct forum to request help, but I could not find a better place. I am trying to setup an httpd server in front of tomcat on centos 5.8.
In the httpd.conf file I have written the below

ProxyRequests off
ProxyPreserveHost on
ProxyPass /static.htm !
ProxyPass / http://localhost:8082/
ProxyPassReverse / http://localhost:8082/


This works fine if I have only 1 static page. I have a little over 34 static pages. Could you please help me figure out how to have multiple static pages serviced by httpd and others go to tomcat?

http://localhost/static1.html ==> static page 1
http://localhost/static2.html ==> static page 2

http://localhost/ ==> should goto tomcat's webapp

Thanks,
Sub
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

Have you considered putting all the static content in one directory and exempting that directory from proxying?

Incidentally, if you are attempting to use http to serve static pages instead of Tomcat merely because "it's more efficient", that hasn't been true for about a decade now.


Customer surveys are for companies who didn't pay proper attention to begin with.
Sub Gowda
Greenhorn

Joined: Sep 23, 2012
Posts: 10
Hi,

Thanks for the reply. I am trying your suggestion and use tomcat to serve my static content also. I still get to see the folder name in the URL where my static pages are stored.

I have multiple directories and static pages inside "myfolder" and I dont want to display "myfolder" in the url. I am ok with displaying the directory names.

example:http://localhost/myfolder/sub/index.html works, but I want it to show as http://localhost/sub/index.html and
http://localhost/myfolder/static1.html works. but i want the url to look like http://localhost/static1.html


Could you please help me out?

Thanks,
Sub
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

If I understand you correctly, you want resources from 2 different sources (apache and Tomcat) to appear as though they were all coming from one source in the URL path.

You can't do that, because someone (Apache, since it gets the first shot) has to have some sort of clue as to which kind of resource it's retrieving in order to know where to get it from. That cue usually would be done as a "directory" in the URL - for example "/images", "/scripts" and "/styles", but an Apache rewrite could also trigger on magic patterns in the resource name (for example, "*.jpg).
Sub Gowda
Greenhorn

Joined: Sep 23, 2012
Posts: 10
Actually I have removed Apache from my system. I have only tomcat 7 on port 80. I followed your suggestion on the earlier post and decided to use only tomcat for both dynamic and static content.

I am still having the same issue as earlier. I want the below to work. Please help..

http://localhost/myfolder/sub/index.html works, but I want it to show as http://localhost/sub/index.html and
http://localhost/myfolder/static1.html works. but i want the url to look like http://localhost/static1.html
K. Gil
Ranch Hand

Joined: Apr 29, 2011
Posts: 75

Tomcat's default app is inside webapps/ROOT
so follow this:
1) take a backup of all your webapps directory
2) remove webapps/ROOT
3) change name of "myfolder" to "ROOT"
4) restart tomcat
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

More correctly, Tomcat's default webapp is webapps/ROOT.
K. Gil
Ranch Hand

Joined: Apr 29, 2011
Posts: 75

More correctly, Tomcat's default webapp is webapps/ROOT.


Thank you for correction
Sub Gowda
Greenhorn

Joined: Sep 23, 2012
Posts: 10
Thanks, I did that. I backed up ROOT folder and then renamed my application.war file to ROOT.war and tomcat deployed it as ROOT. I can see my web application on http://localhost
But i still cannot see my static pages. My static pages are in /usr/share/website/, which is not my in webapps directory(/usr/local/tomcat7/webapps/). My application creates a lot of static (html) pages and is saved in /usr/share/website/. This location is Alias to myfolder in my web application.

example: when some one uses my web application, a new folder with html pages are created and saved in /usr/share/website (myfolder). Lets say the new folder is called "sub".

Now when i point my browser to http://localhost/myfolder/sub/index.html i can see the content of index.html, but
I want the browser to show me the content of index.html, when i use http://localhost/sub/index.html (as of now i see a 404 error)

Basically, I don't want the users to see the word "myfolder" in the URL.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

If you're using filesystem aliases (links), you may need to override Tomcat's default settings. For security reasons, I don't believe that Tomcat will resolve through aliases unless explicitly instructed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ProxyPass from httpd to tomcat