Setting up a production environment using an Apache proxy

In a production environment, it's possible to choose many different architectures. One of the architectures that is widely used is one where the URL is rewritten by an Apache proxy server, so it's friendlier to be called by the user.

Normally, an APEX URL looks something like http://<servername>:<port>/apex/f?p=123:1:32413124434::NO:::: or anything else involving a lot of numbers, colons, and random characters. This is not very easy to understand and very hard to remember.

What we want to deliver to our visitors, is an easy-to-remember URL that will redirect to the underlying APEX page.

In this recipe, we will explain how to use rewrite in the configuration of an Apache Proxy server, so an APEX application can be called by a friendly URL.

Getting ready

Using a simple machine (can be a virtual machine) we have to set up an Apache web server. The software is available at http://httpd.apache.org, but when the server runs a Linux operating system, Apache is already there.

Getting ready

How to do it...

When we investigate the installation directory of Apache, we can find a directory called 'conf'. In this directory, it is a filed name httpd.conf.

  1. Open httpd.conf to edit.
  2. Ensure that the following lines of code are available and not commented:
    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule proxy_module modules/mod_proxy.so
    

[1346_10_3.txt]

These modules will allow Apache to act as a proxy server and rewrite incoming URL requests to the internal representation of the APEX application.

In older versions of Apache, the next steps have to be done in the httpd.conf files. In newer versions, it has to be done in the httpd-vhosts.conf file. To see if we are working with a newer version, see if the following code is available in httpd.conf:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

[1346_10_4.txt]

If this line is present, open httpd-vhosts.conf in the confextra directory. Otherwise, keep editing the httpd.conf file that is already open.

We are going to make some assumptions, so the following code will be more clear.

  • The URL of our website is the fictional website http://www.apexbook.xyz
  • Our APEX application runs on a server with IP address 192.168.0.1 on port 7001
  • We have used the recipes in Chapter 6 and made a translatable application using the LANG request and FSP_LANGUAGE_PREFERENCE
  • The Application ID is 200 and the ID of the login page is 101
  • We want the visitors to be able to use the URL http://nl.apexbook.xyz to directly access the Dutch version of the application

We now have enough information to create the configuration in the .conf file.

  1. Open httpd.conf or httpd-vhosts.conf depending on your situation.
  2. Enter the following code (replace pieces where necessary for your situation):
    <VirtualHost *:80>
    ServerName nl.apexbook.xyz
    ServerAlias nl.apexbook.xyz
    RewriteEngine On
    RewriteRule ^/$ /apex/f?p=200:101::LANG:::FSP_LANGUAGE_PREFERENCE:nl [R=301,L]
    ProxyPass /apex http://192.168.0.1:7001/apex
    ProxyPassReverse /apex http://192.168.0.1:7001/apex
    ProxyPass /i http://192.168.0.1:7001/i
    ProxyPassReverse /i http:// 192.168.0.1:7001/i
    </VirtualHost>
    

[1346_10_5.txt]

What happens is that whenever http://nl.apexbook.xyz is called, the rewrite engine will paste /apex/f?p=200:101::LANG:::FSP_LANGUAGE_PREFERENCE:nl behind it. The Proxy then learns to redirect any call to /apex to http://192.168.0.1:7001/apex (and the other way around, hence the ProxyPassReverse).

To also allow the images directory to be found, we do the same thing for any call to the /i directory.

With this code in place, any call to http://nl.apexbook.xyz will automatically redirect the user to http://192.168.0.1:7001/apex/f?p=200:101::LANG:::FSP_LANGUAGE_PREFERENCE:nl

Much friendlier, isn't it?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.51.157