views:

502

answers:

5

If we are to separate our web server and app server, would we need java on both machines? I've had one coworker say to install jboss on both machines (seems to defeat the purpose if both machines have app server installed) and another says just install jboss on one and apache on the other (app server/web server).

I have the web project setup already and it uses servlets and JSPs. The JSPs display the content while the servlets do the action. The servlets receive requests and forward responses to the JSP. My question is how do I do this if the web server only has apache and therefore displays static content? I understand how to forward the requests from the web server to the app server but what about maintaining session state, is that done on the web server and if so how would it be done?

If the login page is html and the content after the login is html then how could I stop people from accessing the content if they haven't logged in?

A: 

Your scenario reminds me of SiteMinder. It was used to access control into our application. It has built in HTTP forwarding so from the user's perspective the browser talks to siteminder and siteminder talks to the real application. They both use session cookies and siteminder's called SMSESSION while the app's called JSESSIONID so there is no conflict.

kd304
Is it better to just use jboss (or tomcat) on both machines but use one as a web server and one as an app server? At least I could use JSPs on the web server and still use the app server to serve requests.
ravun
That will introduce the need to use RMI or SOAP or (insert remoting technology here, it really doesn't matter) anytime those JSP's need to call any business logic on the appserver. Think LONG and HARD before doing this. Even if everything in your app is already an EJB, the fact that it is currently running all in one JVM means you don't know how it will perform once you separate it.
Licky Lindsay
@ravun I can't really think of a good reason to use that setup as you described. People usually want to use something like Apache to sit in front of the Java app server because it is supposed to be able to serve static content faster (although this can be debatable). So then what benefit do you out of seperating the web server and app server if the web server you are using is just ... another instance of the app server?
matt b
That's what I was thinking also, I'm glad matt b clarified... as well as everyone else. Thanks.
ravun
+8  A: 

The latter setup you describe, with Apache serving static content and forwarding requests for JSP/servlets onto the app server is the standard setup.

Session state is maintained as normal, your Java webapp on the app server sends the user back a cookie containing a JSESSIONID and when the user makes subsequent requests, Apache includes all request info (including cookies) in what it forwards to the app server.

The setup becomes a bit more complicated if you want to have Apache sit in front of and load balance requests to multiple JBoss instances, but it's still pretty easy to set up with mod_proxy_balancer.

Some links that might help you:

http://help.shadocms.com/blog/2009/how-to-setup-apache-with-jboss-on-a-shado-site.cfm http://redlumxn.blogspot.com/2008/01/configure-apache2-and-jboss-422ga.html

matt b
+1  A: 

There are many possibilities.

  1. On web machine install just apache with mod_jk to redirect the requests to tomcat/jboss. In this case you don't need java on this machine.

  2. You can also separate your jsp container (e.g. tomcat/jboss) and your app server in this case you you will need to install java where you have your web container.

  3. Generally where there is a need of higher security people combine the above mentioned possibilities. Thin web layer (apache + no java) + Web container (e.g. tomcat) + app layer (jboss/glassfish)

The first solution is normally the standard one.

rangalo
A: 

A common deployment is to use Apache fronting servers to serve static content and forwarding requests for dynamic content to the JSP server. This is mainly for performance reasons, Apache being both faster at serving content and reducing the load on the JSP server.

I don't see any reason why you couldn't, for example, use IIS as the fronting server (removing Java from the equation), although with the wealth Apache modules and accompanying information about the configuration I think you might be making life difficult for yourself if you did.

Nick Holt
A: 

Short answer - No.

Long answer -

It depends on the needs of your application. There are a few reasons why you would want to have the web server on a different physical machine:

  • You want to have the web server serve the static content, and leave the app server free to only process servlet/jsp content

  • You wish to implement software based load balancing. You would have the
    apache server proxy requests to
    multiple backing app servers

In your login example, the html page is served by apache, and the action of the html form points to your servlet for processing - so JBoss/java will still manage the session. Keep in mind that any static content you want apache to server will need to be present on the web server.

Rich Kroll