This page explains how to set up an Apache HTTP Server (httpd) in front of Tomcat on a local machine for development purposes. This page is not intended as a guide for a system administrator to set up a production environment.
At the end you can access the Magnolia contexts with different domains which both serve from root. This kind of setup may help testing multisite scenarios during local development to emulate a production environment scenario.
This page assumes that you are using a Mac or something similar. This is especially true concerning the paths to Apache configuration files. However, the information here should also apply to other OS.
Start with a Tomcat bundle of your choice, for a selection of bundles see list of preconfigured Magnolia bundles. If you want to test multisite scenarios, choose an EE pro bundle (such as
If want to get rid of the demo modules to start with a vanilla multisite module - remove the appropriate modules before you start the bundle for the first time. (On magnolia-enterprise-pro-demo-bundle delete the modules starting with magnolia-travel* from the folder
Before following the steps explained below, start the bundle as usual, to make sure both webapps magnoliaAuthor and magnoliaPublic are installed and work properly.
This is an overview of the the multisite setup:
|author instance||public instance|
Note that we use only one domain - a subdomain of the "main domain" - to access the author instance (which is recommended practice).
To enable this without DNS, add the following line to your
Make sure you have a working Apache on your local machine.
Helpful Apache commands
Whenever you change Apache configuration files, you have to restart the
Restart the process
Check the configuration
Make sure your Apache has the modules
/etc/apache2/httpd.conf file and make sure the following lines are not commented:
On a different OS, the path and suffix of the modules may be different. If you edit the file, you must restart Apache.
We use virtual hosts configuration in this setup. Make sure
vhosts are enabled. Check the
/etc/apache2/httpd.conf file and ensure the line with the
include directive is not commented:
Define virtual hosts
vhosts is properly enabled, edit the
/etc/apache2/extra/httpd-vhosts.conf file and add something similar to this:
See lines 3, 4 above which are commented: At first sight one may think that these
ProxyPass rules should be sufficient. However, they're not. Some things will work, but especially the multisite setup won't do what we expect .
ajp protocoll to redirect from apache to Tomcat.
mod_jk is a known variant which works too, see apache documentation.
Since we use
ajp - the ajp connector must be configured in the Tomcat
server.xml - which is the case in the default server.xml which is provided by a Magnolia bundle. In the server.xml of your Tomcat you should find an entry as this:
Redirecting to Tomcat root
The apache redirect points to the Tomcat root context (see lines 5, 6 in the excerpt from
httpd-vhosts.conf shown above).
Redirecting to ajp://localhost:8009/magnoliaAuthor - would work, but again, only partially. (Try it out, if you want to have fun.) Web resources would not load and redirections done by Magnolia would be incorrect.
So, since the apache redirect points to the Tomcat root context, we must make sure that the webapp magnoliaAuthor is served from the root context. This needs a few modifications on Tomcat (see below).
Tomcat adjustments to serve one context from root
I guess there are different possible solutions to serve a Magnolia instance from Tomcat root context. Here comes one:
<Context> directive which allows to define the path of a webapp.
"") as value of the
pathattribute ensures to serve the webapp magnoliaAuthor from the root context.
See line 37: Added
Tomcat can serve only one webapp from root within the same host and within the same service.
However, since now we have only one context served from root.
Usage in a production environment
In a productive environment, you probably have 2 hosts / servers in different networks, in which one server contains one Tomcat serving a single instance. If this is true, the setup described above is feasible.
Use in a production environment at your own risk. This page is not intended as a guide for a System administrator.
Serve both contexts from root from localhost
The following, extended setup allows to run and access both Magnolia instances from one Tomcat instance.
Once again, this is a not required setup for productive environments, but it works fine on a local development machine.
These is the demanded setup:
|author instance||public instance|
Keep in mind that we already have defined redirects to
localhost for these three domains (in the
Virtual hosts configuration
In summary we need three virtual hosts on Apache - here is the modified
httpd-vhosts.conf with one virtual host for the author instance and two for the public instances:
- Lines 3-4:
author.best-comics.netredirects to localhost on port 8080
=> author instance
- Lines 9-10, 15-16:
www.best-vinyl.netare redirected to localhost on port 8081
=> public instance
- The lines configuring the log files of the virtual hosts have been removed to keep this configuration excerpt small.
As mentioned above, one Tomcat host cannot serve two contexts from root.
We achieve this by the the following:
- Define two
<Service>sections in the
<Connector>swith distinct ports.
- AJP connector
- HTTP connector *
- Serves from its own
- Defines one host which wraps exactly one context to be served from root.
*) Actually the AJP connector would be sufficient to use tomcat via apache. However, if you also keep the HTTP connector, you can access tomcat also directly. And we also will use the HTTP connector for JCR activations from author to public context.
We assume that the bundle has already been started once and that both webapps have been properly installed.
This is the adapted Tomcat directory structure:
- Create the folder
- Move the webapp
- You may want delete the webapp
ROOT, you won't be able to access it anymore.
This is the
- There are two
nameattributes have different values.
<Service>has its own
<Connector>s with distinct ports
- Each connector must have its own distinct ports on the attributes
portof the AJP-
<Connector>is the same port to which we redirect on the Apache virtual host configuration.
Final adjustments on the Magnolia instance
Adjust the subscriber for content activation
To ensure content activation still works, you have to adjust the property
Note that the activation is using the HTTP connector.
URLs of the final setup
If you have all done correctly - you can access the Magnolia instance by the following URLs
|author.best-comics.net||via Apache and AJP connector|
|author.best-comics.net:8080||via Tomcat and HTTP connector|
|www.best-comics.net||via Apache and AJP connector|
|www.best-comics.net:8081||via Tomcat and HTTP connector|
|www.best-vinyl.net||via Apache and AJP connector|
|www.best-vinyl.net:8081||via Tomcat and HTTP connector|