APEXblog.nl - Tips and Tricks

About This Blog:
I (Richard Weug) started this blog primary for myself to save all kinds of Apex tips and tricks in one place. To use it as a place to write down how I used some coding in my own projects, but also to copy and paste all kinds of articles I find on the Internet. (So I never have to wonder on what website did I read about??? When I see something interesting I collect the content so I have my own archive/knowlegde base.

View my profile on LinkedIn


Installation & Configuration


Apex and HTTPS

Written by Richard Weug. Posted in Installation

Adding HTTPS to Oracle Application Express on Oracle 10g Express

CentOS 5.x
Oracle 10g Express
APEX 3.x upgrade
Apache 2.x

If you are running APEX on Oracle 10g Express, you do not have access to the Wallet Manager per the OTN agreement.

You can still add HTTPS functionality, however, via Apache using mod_ssl.

While pervasive, mod_ssl is a third party module not supplied by Apache. If not already installed, yum install mod_ssl.

Let's start with a non-HTTPS example.

Within our Apache httpd.conf file, we create a reverse proxy to our Oracle APEX application.

There are any number of reasons for doing this:

1. We might do this for domain mapping (i.e. so www.yourdomain.com resolves to a specified application ID and landing page www.yourdomain.com/apex/f?p=101:1)

2. To allow access when behind a firewall where :8080 would block access

3. To increase security by running our Apache installation on a public facing server and back-ending to our Oracle server behind a firewall through which only our Apache server has access.

To create the reverse proxy we can use the following Virtual Host configuration under /etc/httpd/conf/httpd.conf

For simplicity, in the example below, Apache is installed on the same server as Oracle. If your installation is otherwise, simply substitute your server hostname or IP for localhost below.

<VirtualHost *:80>
ServerAdmin This e-mail address is being protected from spambots. You need JavaScript enabled to view it.
DocumentRoot /home/yourdomain.com/htdocs
ServerName yourdomain.com
ServerAlias www.yourdomain.com
ErrorLog logs/yourdomain.com-error_log
CustomLog logs/yourdomain.com-access_log common
RewriteEngine On

RewriteRule ^/$ apex/f?p=101:1 [R=301]

ProxyRequests Off
<Proxy *>
Order allow,deny
Allow from all
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Now, if we want to add HTTPS functionality, we begin by creating our SSL Key, CSR, and Certificate as we would for any standard SSL certificate.

If you have never done this before, RapidSSL has a very simple and useful step-by-step guides to doing so on Apache with OpenSSL and ModSSL:
1. Create Key and CSR: http://www.rapidssl.com/ssl-certificate-support/generate-csr/apache_mod_ssl.htm
2. Install Certificate: http://www.rapidssl.com/ssl-certificate-support/install-ssl-certificate/apache_mod_ssl.htm

If you want to take a practice run, or don't care about the certificate throwing a browser error, you can simply create a self-signed certificate.

I'm going to store my key and crt (certificate) files in the default locations.

With our certificate installed, lets return to the VHOST we created Now, under /etc/httpd/conf/httpd.conf change the Virtual Host we created above to below.

<VirtualHost *:80>
ServerAdmin This e-mail address is being protected from spambots. You need JavaScript enabled to view it.
DocumentRoot /home/yourdomain.com/htdocs
ServerName yourdomain.com
ServerAlias www.yourdomain.com
ErrorLog logs/yourdomain.com-error_log
CustomLog logs/yourdomain.com-access_log common

RewriteEngine on

RewriteRule ^/(.*)$ https://%{HTTP_HOST}/$1 [L,R]


The above rewrite RewriteRule ^/(.*)$ https://%{HTTP_HOST}/$1 [L,R] forces all requests made to :80 HTTP to :443 HTTPS (or whatever port you have configured to handle HTTPS requests).

Now that we have set up VHOST in httpd.conf and created our SSL key and certificate, we know need to create an additional VHOST under  /etc/httpd/conf.d/ssl.conf. The ssl.conf was created when we installed mod_ssl.

Under /etc/httpd/conf.d/ssl.conf configure the Virtual Host as below. I will be creating more than one SSL domain, so I am using IP 123.456.78.90 for this domain and will specify this in the Virtual Host below.

The SSL Virtual Host in our below in our /etc/httpd/conf.d/ssl.conf  file is truncated and I have highlighted the main areas where we have done our configuration in bold. I have also added a few comments in blue.

<VirtualHost 123.456.78.90:443>
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/home/yourdomain.com/htdocs"
ServerName www.yourdomain.com:443

# Note that we have moved the reverse proxy from our httpd.conf file to our ssl.conf file
RewriteEngine on
RewriteRule ^/$ apex/f?p=101:1 [R=301]

ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on

# SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect. Disable SSLv2 access by default:
SSLProtocol all -SSLv2

# SSL Cipher Suite:
# List the ciphers that the client is permitted to negotiate.
# See the mod_ssl documentation for a complete list.

# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
# The path below gives the location where we stored the SSL certificate we created
SSLCertificateFile /etc/httpd/conf/ssl.cert/www.youdomain.com.crt

# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
# The path below gives the location of the key we created.
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/www.youdomain.com.key

SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0

CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"


For Oracle APEX on Windows - I have never used a local Apache installation on W2K3. The simplest method for doing the above would be to use Linux server as front end with the proxy back-ended to the APEX installation on the Windows server. In Windows Firewall, you can then open access to your Linux box.

Footnote - for those new to Apache, the above does not touch on tuning. ReverseProxy and rewrites require tuning in order to perform well. Be sure to set KeepAlive to On, use mod_deflate (or gzip for 1.3), as well as set reasonable prefork MPM and worker MPM values. Apache tuning is beyond the scope of this post, but start with checking the docs and Googling these items to get you going.

Original Article by: David Ghedini