8 Replies Latest reply: Feb 28, 2012 6:39 AM by crokitta RSS

    One IP for Multiple Domains

    691822
      Hi,

      I have installed a DB and a Glassfish on one server. The server should handle 3 domains and only one IP address available which points to this server, each domain has its own Oracle APEX application.

      www.d1.com >>> One IP Address >>> APEX Application1
      www.d2.com >>> One IP Address >>> APEX Application2
      www.d3.com >>> One IP Address >>> APEX Application3

      How can I implement this?

      Thanks,
        • 1. Re: One IP for Multiple Domains
          Udo
          Hi,

          currently, I don't know a way to achieve this kind of mapping directly by using the APEX Listener.
          I'd put a simple HTTP/HTTPS proxy (e.g. Apache HTTP Server) in front of the GlassFish to do the domain-application-mapping. You could use this proxy as well for deploying your static contents (APEX images) instead of putting it on the GlassFish.
          If there are security rules that need to enforce each application to only respond to the appropriate domain, I'd additionally implement that in the authorization scheme of the application.

          -Udo
          • 2. Re: One IP for Multiple Domains
            691822
            Hi Udo,

            Thanks for that.

            I'm very surprised by the way APEX team decided to replace the Apache Tomcat with Glassfish. Glassfish is good product, but if you know that something simple like this can't be achieved by Glassfish and the APEX listener why this issue is not addressed by APEX team.

            I have multiple domains and applications, and simply I can't map these domains to relevant applications. I have tried to send email to kris and the rest of APEX team and they just responded with Read more on Glassfish!

            I'm really reaching deadlock with this, that I can't assign Domains to Applications using the current APEX. We have no choice to change the current architect of this work, we can't add another tier to host Apache.

            Am I the only one who tried to map different domains to different Applications, is not there any one could help on this?

            Thanks,
            • 3. Re: One IP for Multiple Domains
              Udo
              Hi,

              well, the decision to drop Tomcat support probably is part of the global Oracle strategy, and though I personally regret this decision, I understand it: Oracle only wants to support in-house products, which is why you get support for all availabe Oracle J2EE-Containers (OC4J, Sun (now Oracle) GlassFish Enterprise, WLS). The official support doesn't even include the GlassFish Open Source Edition, which is "community-supported". You can run the APEX Listener on Tomcat anyway, you just won't get official support for that scenario.
              I just wonder how you would solve that problem on a plain Tomcat without proxy? The problem, as far as I understand it, is more related to the nature of the APEX Listener to serve the whole APEX instance without focus on a certain application, so even if you make your Listener deployment to be available for a certain domain only, you will always be able to reach any application on the confiugred APEX instance.
              If you don't want or can't use the proxy approach, you may also put a pre-processing procedure into your database that redirects the user according to the URL-referrer. But this can get a pain if you want to have more than one application mapped on a certain domain.

              Perhaps I'm thinking in the wrong direction. If so, please correct me, so I might be able to give you a more fitting answer.

              -Udo
              • 4. Re: One IP for Multiple Domains
                691822
                HI Udo,

                I agree with what you said, it's the corporate strategy.

                Is't possible to install more than on APEX listener and map each listener to different apex domain? Does that solve my issue?

                So if someone hit

                www.domain1.com will take it to APEX application1
                www.domain2.com will take it to APEX application2
                www.domain3.com will take it to APEX application3

                In any language this is extremely easy why in APEX is impossible!

                Thanks,
                • 5. Re: One IP for Multiple Domains
                  Udo
                  Hi,

                  perhaps I was thinking too complicated. I guess it is possible to configure your GlassFish to do that mapping by using Virtual Servers and URL Redirection. And probably you could even use that feature to enforce the use of that application on other domains. Redirects aren't the best solution im my opinion, as they cause additional requests and are not transparent, but you should be able to get that scenario working.
                  The current Administration Guide only has a very small example for [url http://download.oracle.com/docs/cd/E19798-01/821-1751/gixrb/index.html]URL Redirection, but I guess you get what you need there. In a following section, you'll find information on [url http://download.oracle.com/docs/cd/E19798-01/821-1751/ggncs/index.html]Virtual Servers.
                  So what you need to do is create three Virtual Servers (one for each domain) and deploy one Listener there. Then configure redirects to make each domain point to the application-URL you desire (it won't be transparent in that case) and, if wanted or needed, additional redirects to prevent any other application to be called on that domain by redirecting any other call to the intended application-URL again.
                  Additionally, as I mentioned before, you could create a procedure you configure into pre-processing for your Listeners, that checks the referrer and again redirects in case a call to an application was triggered through a different domain than expected.

                  But I'd still recommend the proxy for transparency, performance, ease of use and increased security.

                  -Udo
                  • 6. Re: One IP for Multiple Domains
                    Mindmap
                    Hello,

                    It would be great if APEX team find a smooth way to accomplish this...

                    Regards,
                    Fateh

                    Edited by: Fateh on Feb 18, 2012 5:56 AM
                    • 7. Re: One IP for Multiple Domains
                      Udo
                      Hello Fateh,

                      I'm not sure if it's actually possible to solve that problem in APEX or APEX Listener, as it basically is something that happens at your JEE Container. For instance, you can get a clean setup with the URL Rewrite Filter on Apache Tomcat, because Tomcat lets you inject that servlet into its root context easily. It seems to be more difficult on GlassFish. I've spend a few hours in lab on trying to get it work, but didn't succeed until I had to focus on some other topic. I haven't given up on finding out, but it'll be only adding a solution for that app server, not for all. WLS might be a completely different scenario. OC4J can probably be configured as simple as Tomcat, but it seems that it's rarely used for APEX Listener...
                      So, if at all, the APEX Listener team would have to develop something like the URL Rewrite Filter and/or work on examples on how to get it work on the different supported JEE Containers. I guess, since you can solve this by adding a proxy with rewriting, this won't be a primary target for a future release. But who knows ... ;)

                      -Udo
                      • 8. Re: One IP for Multiple Domains
                        crokitta
                        Hi,

                        I actually had the same problem: I have one oracle instance (11gXE2) with Glassfish and the APEX Listener. I'm hosting different applications (in different workspaces) on this instance. The whole configuration is accessible by one fixed IP adres from the internet. I further have several domains (and sub-domains) mapped to this one IP. To ensure that a request for www.d1.com is routed to Application1 and www.d2.com to Application2 I wrote a smal plsql-"proxy (or multiplexer) using the OWA_UTIL.get_cgi_env ('HOST') variable to determine the requested domain and then redirect to an application that belongs to it.

                        The configuration I have stored in a table, for matching I use LIKE patterns:

                        Table for my "proxy":

                        {code}
                        CREATE TABLE "PROXY_RULES"
                        (     "ID" NUMBER,
                             "SEQ" NUMBER,
                             "HOST_PATTERN" VARCHAR2(1000),
                             "REDIR_URL" VARCHAR2(1000),
                             CONSTRAINT "PROXY_RULES_PK" PRIMARY KEY ("ID") ENABLE
                        ) ;
                        {code}

                        filling for your example:
                        {code}
                        ID SEQ HOST_PATTERN REDIR_URL
                        -- --- ------------ ---------------------------------------
                        1 5 %.d1.com http://www.d1.com/apex/f?p=App1:Home:0
                        3 10 %.d2.com http://www.d1.com/apex/f?p=App2
                        2 15 %.d3.com http://www.d1.com/apex/f?p=App3:1:0
                        ...
                        0 99 % http://www.d1.com/apex/f?p=App1:Home:0
                        {code}

                        and the actual procedure to redirect calls:

                        {code}
                        PROCEDURE redirect IS
                        t_host varchar2 (250);
                        t_redir varchar2 (250);
                        BEGIN
                        t_host := OWA_UTIL.get_cgi_env ('host');

                        SELECT redir_url
                        INTO t_redir
                        FROM (SELECT redir_url
                        FROM proxy_rules
                        WHERE UPPER (t_host) LIKE UPPER (host_pattern)
                        ORDER BY seq, id)
                        WHERE ROWNUM < 2;

                        OWA_UTIL.redirect_url (curl => t_redir, bclose_header => TRUE);
                        EXCEPTION
                        WHEN OTHERS
                        THEN
                        OWA_UTIL.redirect_url (curl => 'http://www.d1.com', bclose_header => TRUE);
                        END redirect;
                        {code}

                        Grant execute on this procedure to the APEX_PUBLIC_USER, create a public synonym on it and make sure all requests without a path get redirected to it, for example with a simple index.html containing a redirect to "/apex/redirect":

                        <meta http-equiv="refresh" content="0; url=/apex/redirect">

                        This works fine, but doesn't check that App2 is accessed through www.d1.com. I still have to add this functionality.

                        I'm using the method on my sites [url http://www.rokit.nl]rokit.nl, [url http://www.fifapex.net]www.fifapex.net, [url http://m.fifapex.net]m.fifapex.net, [url http://www.themes4apex.com]www.themes4apex.com and [url http://www.themes4apex.com]www.themes4apex.nl. Try it!

                        I hope this helps.

                        Regards,
                        Christian Rokitta

                        Edited by: crokitta on Feb 28, 2012 1:38 PM

                        Edited by: crokitta on Feb 28, 2012 1:39 PM