Wednesday, January 4, 2012

Running Artifactory with Tomcat behind Apache HTTPD

At work we're setting up some new Artifactory instances in the AWS cloud, using all the latest gizmos - Ubuntu 11, Java 7, a dedicated Tomcat instance as the Web container and MySQL as the data store. We wanted to run Tomcat behind Apache HTTPD as the default application; this took a few tries before we got it right, so I'm posting the details here as I didn't find many results when Googling.

The following assumes you're using a dedicated Tomcat instance to run Artifactory and that you've used their $ARTIFACTORY_HOME/bin/tomcat-install.sh script to do a standard installation, so that Artifactory is listening on http://yourhost.yourdomain:8081/artifactory, with an AJP listener on port 8019.

Install mod_proxy_ajp:

sudo a2enmod proxy_ajp

Set up the Apache site configuration to proxy requests to Artifactory - default config file under Ubuntu is /etc/apache2/sites-enabled/000-default

ProxyPreserveHost on
ProxyPass / ajp://localhost:8019/artifactory/
ProxyPassReverse / http://yourhost.yourdomain/artifactory
ProxyPassReverseCookiePath /artifactory/ /

Add these lines just before the end of the VirtualHost section.

Restart Apache:

sudo service apache2 restart

Now Artifactory should respond on http://yourhost.yourdomain

Finally, go to the Admin tab in Artifactory, select General in the left toolbar and set the Custom URL Base field to http://yourhost.yourdomain