1

I've seen a lot of discussion on the best way to use Apache as a proxy (either mod_proxy or mod_jk) with Glassfish (and other Java application servers), but I haven't seen anybody really explain why.

My setup right now is a single VPS running Ubuntu Server with Glassfish accepting HTTP requests on port 8080 (iptables forwards port 80 requests to port 8080 so I don't have to run Glassfish as root). I run a few small websites.

My site is divided into two main parts: static and dynamic. They are each on a separate subdomain. It would be easy to handle the static content with Apache (or another web server) and then use Apache as a proxy for the dynamic content, but is there any reason to do that?

If I were to use Apache, it would ideally have to run in less than 100 MB of memory to save room for everything else running.

Using a recent application server (Glassfish 3), will I get any performance benefit by using Apache as a proxy?

2 Answers 2

3

How good is Glassfish at serving static content? Name-based vhosting? Redirects? I'm willing to bet that Apache is better at it all. If you're particularly interested in a small footprint frontend webserver, though, look at nginx instead of Apache.

0

There are lots of reasons why you would consider using a reverse proxy in front of a Java application server:

  • On Linux you should not be running GlassFish as root, but you cannot use port 80 or 443 unless you are root. A reverse proxy is one way around this. Other ways around this include xinetd and iptables. Alternately you can just not use standard web ports (not user or SEO friendly).
  • If you already have an existing web server squatting on the port you want you can "share" it via reverse proxy. For example put PHP apps and Java apps both on port 80 of same web server.
  • Apache is better tested (used a lot) and more secure than GlassFish (not used much) so it can protect it from direct access. For example Security experts (SANS) advise using a three tier architecture where the front web server is in a DMZ and the application server is in a middle security level (and database is in third even more secure network).
  • You can make changes to application server without users being aware (for example, rename it or split it from one to many).
  • May have better performance with static content (can use native OS File access -- but GlassFish can cache static content in memory if you tell it to so this could be negligible)
  • More familiar URL Rewriting, Redirects, Custom headers, Caching, virtual hosting (note: GlassFish does all of these things or can do them with custom Servlet Filters or 3rd party Servlet Filters like Tuckey URLRewrite).

You must log in to answer this question.