Removing the Port Number from CollectionSpace URLs

The below are notes, rather than official documentation.

They were originally done for Ubuntu, retried and refitted on Debian. They should translate pretty straightforwardly to other OSes.

This document explains how to remove the port numbers that are usually required for CollectionSpace. This is achieved by using the Apache HTTP Server's rewrite module. The end result is that a regular CollectionSpace URL:

http://qa.collectionspace.org:8180/collectionspace/ui/core/html

can be prettified somewhat by removing the :8180, like so:

http://qa.collectionspace.org/collectionspace/ui/core/html

Besides removing the port number from the URL, this can be used for handling cross domain issues (e.g. for acceptance testing with DOH), or rewrites of URLs for other purposes

Setting up Apache

Make sure you have apache2, php5, mod_rewrite, mod_proxy, proxy_http installed:

sudo apt-get install apache2 php5 apache2.2-common libapache2-mod-proxy-html

Then make sure these modules are enabled. How to do this depends on your OS, as a general rule these can be set under your httpd.conf using AddModule.

In Ubuntu and Debian, this is done like so:

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_connect 
sudo a2enmod rewrite

Next, set up the rewrite rules. These can be set in several places. If you just have a single domain on your computer (ie. localhost), this should be settable in the standard /etc/httpd/conf/httpd.conf file under eg. Fedora, and /etc/apache2/sites-enabled/000-default under debian/ubuntu. Add the following in the Virtual Host directive, and change nightly.collectionspace.org for whatever hostname.

RewriteEngine on
RewriteRule     ^/collectionspace/(.*) http://nightly.collectionspace.org:8180/collectionspace/$1 [P]

The next step might not be necessary in all OS/setups - but it was under ubuntu and debian. In the same file, add:

# set server name
ProxyPreserveHost On
ServerName localhost

As a final step in Ubuntu (this might not be necessary on your install), the proxy from needs to be enabled. This is done by fixing the /etc/apache2/mods-enabled/proxy.conf file:

<IfModule mod_proxy.c>
  ProxyRequests Off
  <Proxy *>
    Order deny,allow
  </Proxy>
  ProxyVia On
</IfModule>

You should now be done. Restart your apache server:

/etc/init.d/apache2 restart

Start up a browser, and marvel at the wonder: http://nightly.collectionspace.org/collectionspace/ui/html

If you receive 403 Forbidden error codes when loading your proxied url then make sure you add in a proxy block to your configuration (or virtual host) that explicitly allows proxying. For example:

<Proxy *>
      Order deny,allow
      Allow from all
</Proxy>

Then reload the apache server configurations

/etc/init.d/apache2 reload