13 Replies Latest reply on Mar 7, 2012 6:00 AM by Ronald Rood

    how to make 1 Apache server service multiple APEX installations ?

    Ronald Rood
      hi all,

      what I want is the ability to use 1 http[s] listener that connects to an APEX installation depending on a part of the url. Currently I have apex listener up and running but I don't seem to be able to give Apache something to JkMount or proxyForward to because the APEX installation keeps telling me it is on /APEX instead of - for example - on /inst1/APEX

      What I would like to have is /inst1/APEX -> some apexListener:port that connects to it's own APEX installation. I get the feeling this can not be done using the standalone apex listener but have no idea what else. Could jboss be an option? (how?)

      thanks,
      Ronald.
        • 1. Re: how to make 1 Apache server service multiple APEX installations ?
          Udo
          Hi Ronald,

          if I don't get you wrong, you have a Apache HTTP Server infront of your APEX Listener, right?
          If achieving the effect by proxying would be sufficient, you just need to add a reverse proxy path, e.g.
          ProxyPass               /inst1/apex                       http://<listenerhost>:<listenerport>/apex
          ProxyPassReverse        /inst1/apex                       http://<listenerhost>:<listenerport>/apex
          Note that depending on the APEX versions you'll also have to consider hosting different versions of static contents ("images") on your proxy by either adding proxy rules to these as well or by hosting these on your Apache HTTP Server directly. Either way, you'll need a different context root for each instance with different contents, so you might have to change the image prefix of each APEX instance from +/i/+ to a distinguishable value.
          We have several APEX instances running behind one proxy that way without any problem.

          If that's not what your scenario looks like, please help me get it right.

          -Udo
          • 2. Re: how to make 1 Apache server service multiple APEX installations ?
            Udo
            Just another point that is worth to mention: You need to configure your JEE Server to use that proxy as well. Since it is implemented differently on each JEE Server I know, you should inquire the documentation of your software. I can give you two examples out of my mind:
            For GlassFish, it would be in the JVM options, which can either be set via GUI in "Application Server" or using the commandline as follows
            asadmin create-jvm-options "-Dhttp.proxyHost=myproxy.mydomain"
            asadmin create-jvm-options "-Dhttp.proxyPort=myproxy.port"
            In Tomcat (not officially supported by APEX Listener), you would add the following parameters to your Connector in the server.xml accordingly:
            proxyName="myproxy.mydomain"
            proxyPort="myproxy.port"
            I think this is what's changing your reponses to the desired patterns, i.e. makes the response actually go through the proxy rather than to the client directly.

            -Udo
            • 3. Re: how to make 1 Apache server service multiple APEX installations ?
              Ronald Rood
              Hi Udo,

              thanks for your answer, I will check it out ASAP. I asume I should use the http for the proxyforward instead of the ajp port.
              I will post the results as soon as I have them,

              Ronald.
              • 4. Re: how to make 1 Apache server service multiple APEX installations ?
                Udo
                Hi Ronald,

                my example concerned plain HTTP proxying. AJP would be configured similar on Apache HTTPD side, e.g.
                ProxyPass /inst1/apex ajp://<listenerhost>:<listenerport>/apex/
                ProxyPassReverse /inst1/apex ajp://<listenerhost>:<listenerport>/apex/
                Note that the AJP port will be different from your HTTP port. It depends on your JEE Server how you define that port and how you'll have to configure it to work with your proxy.

                -Udo
                • 5. Re: how to make 1 Apache server service multiple APEX installations ?
                  Ronald Rood
                  Hi Udo,
                  I finally found some time to play further. I simplified the httpd.conf a little.

                  Apache runs on WEBHOST
                  ApexListener runs on APEXLISTENER:8080 (http)

                  So now I have in httpd.conf:
                  ProxyPass /z/ http://APEXLISTENER:8080/apex/
                  ProxyPassReverse /z/ http://APEXLISTENER:8080/apex/
                  # Set Alias /i/ for Apex images , js ...
                  Alias /i/ /usr/local/apex/images/

                  hoping to see HOST/z/ give me a nice apexlogin screen.
                  Instead I get: The page isn't redirecting properly
                  Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
                  This problem can sometimes be caused by disabling or refusing to accept cookies.

                  in access_log I get:
                  192.168.2.3 - - [02/Jan/2012:17:00:08 +0100] "GET /z/f?p=4550:1:433113564243039::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:08 +0100] "GET /z/f?p=4550:1:2471316863673402::::: HTTP/1.1" 302 211
                  192.168.2.3 - - [02/Jan/2012:17:00:08 +0100] "GET /z/f?p=4550:1:683437430754269::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:08 +0100] "GET /z/f?p=4550:1:3646340989273887::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:1071496430827508::::: HTTP/1.1" 302 209
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:8733965940265::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:6881590464816494::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:3195995388325386::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:3830491498944462::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:3471592116251324::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:1507614348452684::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:1799299583120104::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:4388802555391017::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:4285905244336228::::: HTTP/1.1" 302 211
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:141003280736376::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:2500592855388328::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:1960570738682134::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:2828431960971729::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:3718397141206451::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:4100740407575959::::: HTTP/1.1" 302 212
                  192.168.2.3 - - [02/Jan/2012:17:00:09 +0100] "GET /z/f?p=4550:1:1944280806534209::::: HTTP/1.1" 302 212

                  The request reached APEX, APEX returned something but in between there is a problem. Databases are my game, not Apache. Do you have a nice pointer that could help me solve this? [http://www.addedbytes.com/for-beginners/http-status-codes/|http://www.addedbytes.com/for-beginners/http-status-codes/] Redirection is taking place, how can I stop this from looping?

                  FWIW:
                  apachectl -version
                  Server version: Apache/2.2.20 (Unix)
                  Server built: Sep 8 2011 18:13:15

                  both WEBHOST and APEXLISTENER are running maxosx 10.7.2

                  When using APEXLISTENER:8080 directly, it does work ok, at least, I do get the logon screen.

                  Thanks,
                  Ronald.
                  • 6. Re: how to make 1 Apache server service multiple APEX installations ?
                    Udo
                    Sorry for the late response. I hoped I could get access to our testing environment within the last few days to build a clean setup. Unfortunately, either the test site or my schedule haven't allowed to do this and it's not going to be better within the next two weeks...

                    But I have a thought on that problem and perhaps sharing it with you helps you to get further anyhow.
                    I see you have an 'asymetric' context mapping, and this can be quite a challenge for the configuration. (I know I made it sound easier - sorry for that.)
                    Could you try to make your setup to use a similar context on both proxy and JEE server, i.e. use the follwing configuration:
                    ProxyPass        /apex http://APEXLISTENER:8080/apex
                    ProxyPassReverse /apex/ http://APEXLISTENER:8080/apex
                    Either way, as I mentioned before, you need to setup the proxy in your JEE server as well. This is needed to let servlets (applications) be aware of the "public" address it answers the requests for, i.e. the JEE Server is aware it is used behind a proxy and gives the proxy address back upon calls like request.getServerName() .
                    I'm not sure which JEE server you are using, but it seems like you are using the APEX Listener in Standalone Mode. As far as I know, the emdedded JEE (Grizzly) used in Standalone Mode doesn't offer that functionality for its HTTP Connector. But it's offering and AJP-Connector, so if you change from HTTP to AJP as proxy protocol, you should get your APEX Listener scenario to work as expected as well.
                    To do that, you'll have to do enable AJP on APEX Listener and configure your Apache accordingly.
                    Steps:
                    1. include the parameter -Dapex.ajp followed by the AJP port number (common port number would be 8009) in your APEX Listener's startup, e.g.
                    java -Dapex.ajp=8009 -jar apex.war
                    2a. enable mod_proxy_ajp in your httpd.conf
                    2b. use some slightly different proxy rule
                    ProxyPass        /apex ajp://APEXLISTENER:8080/apex
                    ProxyPassReverse /apex ajp://APEXLISTENER:8080/apex
                    Perhaps you have more luck to find time for testing this scenario... It should work that way, but I can't verify the setup.

                    -Udo
                    1 person found this helpful
                    • 7. Re: how to make 1 Apache server service multiple APEX installations ?
                      Ronald Rood
                      Hi Udo,

                      I guess we are all a bit busy these days .... that is good.
                      I tried the symetric solution using ajp and that works.

                      java -Dapex.ajp=8009 -jar apex.war
                      on host APEXLISTENER

                      Now I am very interested in having it work in a slightly different way, where I can use any url on the Apache server.
                      As soon as I change
                      ProxyPass /apex ajp://APEXLISTENER:8009/apex
                      ProxyPassReverse /apex ajp://APEXLISTENER:8009/apex
                      to
                      ProxyPass /zzz ajp://APEXLISTENER:8009/apex
                      ProxyPassReverse /zzz ajp://APEXLISTENER:8009/apex

                      The browser gets hurt with 'The requested URL /apex/f was not found on this server.' So it still is not working as I hoped for because I have several instances of APEX running and want to serve them all using the same Apache server. For this I need some url that makes them all unique ....
                      Your input is VERY welcome,
                      thanks so far,
                      Ronald.

                      Edited by: Ronald Rood on Feb 10, 2012 7:43 PM
                      • 8. Re: how to make 1 Apache server service multiple APEX installations ?
                        Udo
                        Hi Ronald,
                        I guess we are all a bit busy these days .... that is good.
                        Basically ... yes. On the other hand, ... but one can't have everything at the same time, right?
                        java -Dapex.ajp=8009 -jar apex.war
                        ... so, your APEX Listener (or the embedded Grizzly that hosts it) doesn't know it's behind a proxy...
                        I'm not sure the Grizzly acutally uses this parameter, but you could try to add them anyway
                        -Dhttp.proxyHost=proxy -Dhttp.proxyPort=port
                        So it still is not working as I hoped for because I have several instances of APEX running and want to serve them all using the same Apache server.
                        Well, the main problem is, you're using the Standalone Mode. Despite the fact this is not the recommended deployment for productive instances, the Standalone Mode has that kind of hard coded context "apex", so you'd always run into that "asymmetric" problem. You could avoid it by using a "fully-featured" JEE Container, so you could deploy the APEX Listener multiple times on the same service using different contexts (e.g. apex1, apex2, ...) for each instance. In that scenario you could use a symmetric mapping, if you need the proxy in front at all.
                        If you want to stay with your scenario, there is an interesting [url http://www.humboldt.co.uk/2009/02/the-mystery-of-proxypassreverse.html]post on AJP vs. Reverse Proxying. Keep in mind that the example there assumes a mapping of a FQDN to a localhost, which might be more complex than your setup. I'm not sure if it's actually correct for the way APEX (Listener) produces redirects, but I still wasn't able to test. We usually use the symmetric way, which works without any issues...

                        -Udo
                        • 9. Re: how to make 1 Apache server service multiple APEX installations ?
                          Ronald Rood
                          Hi Udo,

                          thanks for your responses. So the standalone apexListener can't be configured to do this ...
                          (I just tested all suggestion I found in your references and my requests seem to be passed through to apex, the way back something goes wrong, I keep ending up with /apex/ in the returned url.)

                          Could this be done by wrapping it up in jboss?
                          (how should that be done?)

                          thanks,
                          Ronald.
                          • 10. Re: how to make 1 Apache server service multiple APEX installations ?
                            Udo
                            Hi Ronald,

                            I guess APEX Listener doesn't only use request.getServerName() but also codes the context it has been deployed to in into the URL paths. Obviously, the context in Standalone Mode is +/apex+ and can't be changed to the embedded architecture. I guess one could do a lot with rewriting and other header manipulation, but I still didn't have time to play around a bit, and I doubt it actually can work for productive sites where such URL-Paths don't only occur in headers, but also in the page content because somebody queried the headers - and the last instance for that has to be the context the APEX Listener actually runs in... The reverse proxy can only rewrite headers, no contents or types of the requests.

                            So, since you seem to be ready to consider running APEX Listener on a "real" JEE Container...
                            Could this be done by wrapping it up in jboss?
                            I guess so, though I'm not very familiar with JBoss and I haven't deployed APEX Listener on JBoss myself yet. Of course, it's not officially supported. A few weeks ago Mukesh posted that he managed to get APEX Listener work on JBoss 7.02: {message:id=10028940}. I skimmed through his blog post he referenced and came to the conclusion that I'll put JBoss on my testing list (worked on whenever there will be time for it...), as I can't beleive this container is so weird that you'd have to put static contents outside and edit templates to get it work.
                            Just for curiosity: Is there any special reason why you think of JBoss? There are other options out there that are known to have a pretty straight forward deployment scenario for APEX Listener... ;)

                            -Udo
                            • 11. Re: how to make 1 Apache server service multiple APEX installations ?
                              Ronald Rood
                              Hi Udo,

                              jboss is not supported for the released ApexListener. GlassFish is.
                              So what I did is install GlassFish from http://www.oracle.com/technetwork/middleware/glassfish/downloads/index.html and deployed ApexListener on it. In GlassFish I could edit the application and give it a choosen Context Root, for which the default is /apex. In Apache I used ProxyPass and ProxyPassReverse to the http listener on GlassFish.

                              ProxyPass /Context_Root/ http://glassfish_host:8080/Context_Root/
                              ProxyPassReverse /Context_Root/ http://glassfish_host:8080/Context_Root/

                              No need to change anything in apex, no need to use the JK Listener in GlassFish. The Apex installation can now be reached from my Apache host and also at the same time on the http://glassfish_host:8080/Context_Root/ It works like a charm and is real easy to setup.

                              For some reason, the Context_Root is fixed on both sides of the ProxyPass. It looks like
                              ProxyPass /Context_Root/ http://glassfish_host:8080/Some_Where_Else/
                              could work but it does not. At least, I could not get that to work, the Some_Where_Else is reached but it returns with at redirection that won't end.

                              For me this is enough, it is good to know that Context_Root should be the same on both sides (not using virtual hosts, just a part of an url)
                              Thanks for thinking with me.

                              Edited by: Ronald Rood on Mar 5, 2012 9:19 PM
                              • 12. Re: how to make 1 Apache server service multiple APEX installations ?
                                Udo
                                Hi Ronald,
                                For some reason, the Context_Root is fixed on both sides of the ProxyPass.
                                ... which is what I experienced as well, at least if you don't use additional rewriting features. But I doubt this will work in all scenarios, especially when applications start using the request uri...
                                Thanks for thinking with me.
                                My pleasure. It helped me get some things straight as well. ;)

                                Please also mark this thread as answered if you think your problem is solved.

                                Thanks,

                                Udo
                                • 13. Re: how to make 1 Apache server service multiple APEX installations ?
                                  Ronald Rood
                                  deploying ApexListener makes this a piece of cake.