You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Malcolm Gorman <ma...@gmail.com> on 2008/04/12 12:23:59 UTC

Is it possible to serve static pages from Tomcat?

During development I want to serve static JSON files to my AJAX
application. Serving
it from an Apache web server on the same server URL but different port
number (different
from my Tomcat port number) gives me a same origin policy error in
Firefox (though not IE). To get around this quickly, I thought I'd
serve static content from Tomcat itself, using
the same port. But how?

I've Googled on this and read the Tomcat FAQs and even JBoss FAQs on serving
static content from Tomcat. All of them say it's slow and you wouldn't
want to do it,
and to proxy to your Apache web server instead. I don't want to do
that, for various
reasons, but if I have to, I will.

The closest I've found to a technique for serving static content from
Tomcat is at:

http://wiki.jboss.org/wiki/ExternalDirectories

Here is the relevant part of that link:

BEGIN >>
 Serving Static External Files in standalone Tomcat Instances (not the
Tomcat instance bundled with JBoss)
If you wish to serve static content from a directory external to
webapps, you can add "Context" element to the Host element in the
server's "server.xml"

       <Host name="localhost" ...>
           <!-- ADD static benchmark DIRECTORY -->
           <Context path="/benchmark" appBase=""
                   docBase="/home/anil/benchmark"
                   debug="99" reloadable="true">
           </Context>
       ...
      </Host>

This will enable Tomcat to serve up static content (like html, images
etc) from a directory /home/anil/benchmark and the url will be
http://localhost:8080/benchmark
<< END

I tried a few permutations of this late Friday with no success.

(1) Is it possible to serve static content with Tomcat?

(2) Is the JBoss example above sufficient? Should I persevere with it?

(3) Is there a Tomcat FAQ or other document that I have completely
missed that explains all?

Any assistance would be very much appreciated!

Regards, Mal.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Is it possible to serve static pages from Tomcat?

Posted by Francis Galiegue <fg...@gmail.com>.
2008/4/12, Malcolm Gorman <ma...@gmail.com>:
> During development I want to serve static JSON files to my AJAX
>  application. Serving
>  it from an Apache web server on the same server URL but different port
>  number (different
>  from my Tomcat port number) gives me a same origin policy error in
>  Firefox (though not IE). To get around this quickly, I thought I'd
>  serve static content from Tomcat itself, using
>  the same port. But how?
>
>  I've Googled on this and read the Tomcat FAQs and even JBoss FAQs on serving
>  static content from Tomcat. All of them say it's slow and you wouldn't
>  want to do it,
>  and to proxy to your Apache web server instead. I don't want to do
>  that, for various
>  reasons, but if I have to, I will.

They're right, you know...

You can do something like this:

* configure a Coyote HTTP connector (but I guess you've done that already),
* in your Apache conf file:

NameVirtualHost x.y.z.t:80

<VirtualHost your.server.name:80>
        ServerName your.server.name
        #
        # DO NOT FORGET THE TRAILING SLASHES!
        #
        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
</VirutalHost>

This way, Tomcat will serve everything AND your 8080 port will not
even show in the URL. Heck, your Tomcat/JBoss can even be on a
different machine (just change localhost).

-- 
Francis Galiegue, fgaliegue@gmail.com
"When it comes to performance, weight is everything" - Tiff Needell

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Is it possible to serve static pages from Tomcat?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> Malcolm Gorman wrote:
> I've Googled on this and read the Tomcat FAQs and even 
> JBoss FAQs on serving static content from Tomcat. All
> of them say it's slow and you wouldn't want to do it,

I don't know where you've been reading that, but it's certainly wrong
these days.  It was true several years ago, but hasn't been for some
time.  No reason to overly complicate your life by including more path
length and more configuration and more maintenance for no benefit.
There are reasons to use httpd in front of Tomcat, but serving static
content isn't one of them.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Is it possible to serve static pages from Tomcat?

Posted by Mark Thomas <ma...@apache.org>.
Malcolm Gorman wrote:
> I've Googled on this and read the Tomcat FAQs and even JBoss FAQs on serving
> static content from Tomcat. All of them say it's slow and you wouldn't
> want to do it,

The Tomcat performance FAQ certainly does not say that. Try reading it again.
http://wiki.apache.org/tomcat/FAQ/Performance_and_Monitoring

> The closest I've found to a technique for serving static content from
> Tomcat is at:

Just put the content in the webapp - just like you would for a jsp.

So, if you have (with a default install):
$CATALINA_HOME/webapps
                 /myApp
                   /dynamic.jsp
                   /static.html

You would use the following URLs:
http://localhost:8080/myApp/dynamic.jsp
http://localhost:8080/myApp/static.html

Adjust as necessary for your appBase, domain, port, appname etc.

Mark


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Is it possible to serve static pages from Tomcat?

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Malcolm Gorman [mailto:malcolm.gorman@gmail.com]
> (1) Is it possible to serve static content with Tomcat?

Yes.

> (2) Is the JBoss example above sufficient? Should I persevere with it?

It's rather odd.  Chuck's suggestion works far better.  Do you *need* JBoss, or will Tomcat suffice?

> (3) Is there a Tomcat FAQ or other document that I have completely
> missed that explains all?

Principally the Servlet spec.  Some of the Tomcat doc tends to assume you've read up on the spec first!

Incidentally, I bet you'll saturate your network bandwidth (or rarely your disk bandwidth!) before you saturate a modern Tomcat's ability to serve static content.  Have a read of http://tomcat.apache.org/articles/benchmark_summary.pdf and note the machine specs against a modern box - Peter saturated a 100 Mbit LAN using a P450 desktop.

                - Peter (a different one)

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org