9 Replies Latest reply on Mar 5, 2010 1:54 PM by Magnus Tengdahl

    JBoss running Seam behind Apache

    Florian Petersen Newbie
      Hello,
      maybe a newbie question ;-) I want to put a JBoss (5.1) running the Seam Framework behind an Apache (2.2) webserver. My application uses links like <s:link view="/somepage.xhtml" .../> My JBoss runs on port 8080, and i use the ProxyPass directives to pass requests to Apache's port 80 to JBoss' port 8080:

      <VirtualHost *:80>
          ServerName myserver
          ProxyPass /app http://localhost:8080/app
          ProxyPassReverse /app http://localhost:8080/app
      </VirtualHost>

      This works for the initial request, so if i call http://myserver/app, my JBoss application shows up correctly.
      The problem now is that the mentioned links are rendered like this:
      <s:link view="/somepage.xhtml" .../> => <a href="http://localhost:8080/app/somepage.seam" ...>...</a>
      But of course they should be rendered <a href="http://myserver/app/somepage.seam" ...>...</a>

      So how can i forward the requests transparently? Rewrite Rules? mod_jk? I expect this to be a standard problem, and i have found some entries saying mod_jk is the default choice for putting JBoss behind Apache, but i still don't know if this solves my problem...

      So thanks a lot for your help,
      best regards
      Flo
        • 1. Re: JBoss running Seam behind Apache
          Florian Petersen Newbie

          I think the ability of setting some kind of base URL in Seam would also help, but i didn't find...
          Thanks again.

          • 2. Re: JBoss running Seam behind Apache
            Frank Stolle Newbie
            Your usage for ProxyPassReverse is okay, but this directive doesn't parses the HTML-Code. See docu at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse

            If you use mod_jk the information about host (hope so) and port (i'm sure) should be transferred to the jboss server dynamically.
            If the generated link then still includes localhost, you also have to adjust the virtualhost settings at the tomcat configuration.
            • 3. Re: JBoss running Seam behind Apache
              Matt Drees Master

              I think you will want to adjust the proxyName and potentially proxyPort settings on the http connector config in tomcat's server.xml.  See the Tomcat docs  for details on these settings.


              In jboss 5.1, I believe the server.xml is inside the deploy/jbossweb.sar directory.

              • 4. Re: JBoss running Seam behind Apache
                Marcus Smedman Newbie

                I was just about to do this config (Apache 2.2 proxy to JBoss 5.1) on my environment and followed your input.


                It works fine as far as I have tested.


                What I did (I run my JBoss on port 15080):


                1. Add this in httpd.conf for Apache:


                # Listen for virtual host requests on all IP addresses
                NameVirtualHost *:80
                
                <VirtualHost *:80>
                     ProxyPreserveHost On
                     ProxyPass /myapp http://localhost:15080/myapp
                     ProxyPassReverse /myapp http://localhost:15080/myapp
                     ServerName localhost
                </VirtualHost>
                
                # Not added actually, just removed comment on these 2:
                LoadModule proxy_module modules/mod_proxy.so
                LoadModule proxy_http_module modules/mod_proxy_http.so
                



                2. Edit deploy/jbossweb.sar/server.xml to include proxyPort in my connector:


                <Connector protocol="HTTP/1.1" port="15080" address="${jboss.bind.address}" 
                               connectionTimeout="20000" redirectPort="15443" 
                               proxyPort="80"/>



                Thanks a lot for the pointers and hope it works for you too Florian!

                • 5. Re: JBoss running Seam behind Apache
                  Christiaan Ypma Newbie

                  I was trying to do exactly this today, was missing only the Edit deploy/jbossweb.sar/server.xml part. Thanks a lot!

                  • 6. Re: JBoss running Seam behind Apache
                    Florian Petersen Newbie

                    Uuuh, thanks a lot all for your input!
                    For any reason i did not receive a mail notification when your messages came in. Now i did, but in the meantime i managed the job using modjk... I see the proxy solution would have been a lot easier, but i think i insist on modjk now cos maybe later some kind of load balancing will be interesting for us anyway...


                    Nevertheless, thanks again (especially to Matt), and i think the proxy solution will help many others as i read from the last posts!
                    Best regards,
                    Flo

                    • 7. Re: JBoss running Seam behind Apache
                      Marcus Smedman Newbie



                      i managed the job using mod_jk...



                      Is it possible for you to share the steps you followed to fix it the mod_jk way?

                      • 8. Re: JBoss running Seam behind Apache
                        Ilya Dyoshin Novice

                        Marcus Smedman wrote on Dec 18, 2009 13:08:


                        Is it possible for you to share the steps you followed to fix it the mod_jk way?


                        Well, sorry for interruption.But I can provide a simple info on this. Solved this problem recently and now I'm happy to share my steps :)


                        for simple modjk installation you should install the modjk.


                        than somewhere in the httpd.conf you should load the module:


                        LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so



                        it's better to do in place where all modules loaded. (if you in ubuntu environment after installing modjk it becames enabled automatically).

                        then you need to specify some configuration for the mod
                        jk beware not to use this inside of virtual host - it should be defined in global scope of apache.


                        # Where to find workers.properties
                        JkWorkersFile /etc/apache2/workers.properties
                        # Where to put jk shared memory
                        JkShmFile     /var/log/apache2/mod_jk.shm
                        # Where to put jk logs
                        JkLogFile     /var/log/apache2/mod_jk.log
                        # Set the jk log level [debug/error/info]
                        JkLogLevel    info
                        # Select the timestamp log format
                        JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "



                        where /etc/apache2/workers.properties is the most interesting part where you can define some balancing. or simply access to the server :) just for beginning it shoud look like this:


                         # Define 1 real worker using ajp13
                        worker.list=worker1
                        # Set properties for worker1 (ajp13)
                        worker.worker1.type=ajp13
                        worker.worker1.host=localhost
                        worker.worker1.port=8009
                        



                        if you haven't modified the jboss installation the port is 8009, if you modified - you should use what you configured for tomcat's ajp accessor.


                        and this is almost everything. Now you can inside of any VirtualHost environment add the jk's worker:


                        <VirtualHost *:80>
                             ServerAdmin webmaster@localhost
                             # Send servlet for context /examples to worker named worker1
                             JkMount  /* worker1
                             ErrorLog /var/log/apache2/error.log
                        
                             # Possible values include: debug, info, notice, warn, error, crit,
                             # alert, emerg.
                             LogLevel warn
                        
                             CustomLog /var/log/apache2/access.log combined
                        </VirtualHost>
                        



                        that's all you need for simple start.



                        Regards!


                        Ilya Dyoshin

                        • 9. Re: JBoss running Seam behind Apache
                          Magnus Tengdahl Newbie

                          I've set up JBoss behind Apache on two different Linux distributions (Ubuntu 9.10 and Fedora 12) using Marcus suggestion above. The details on how to do this differed slightly so I thougt I'd share my knowledge here.


                          For Fedora, Marcus suggestion works perfectly with one addition. The following SELinux rule must be enabled:


                          Allow HTTPD scripts and modules to connect to the network



                          For more info, consult this link: http://www.dharwadkar.com/weblog/apache_fc6_01


                          For Ubuntu, after installing Apache using apt-get, the file structure was slightly different. Instead of modifying httpd.conf I had to modify ports.conf. Also, I had to add one more rule to the virtual host. Something like this.


                          <VirtualHost *:80>
                               ProxyPreserveHost On
                               ProxyPass /myapp http://localhost:15080/myapp
                               ProxyPassReverse /myapp http://localhost:15080/myapp
                               ServerName localhost
                          <Location /myapp>
                               allow from all
                          </Location>
                          </VirtualHost>



                          I also manually had to enable the two necessary modules. This can be done with the a2enmod command.


                          /Magnus