The setup:
server
subdomains:
Step 1: Get your tomcat and subwikis running. Verify.
- http://wikiserver.example.com:8080/xwiki
- http://wikiserver.example.com:8080/xwiki/wiki/subwiki1/view/Main/
- http://wikiserver.example.com:8080/xwiki/wiki/subwiki2/view/Main/
Step 2: get your apache configuration correct. Verify.
- http://wikiserver.example.com/xwiki
- http://wikiserver.example.com/xwiki/wiki/subwiki1/view/Main/
- http://wikiserver.example.com/xwiki/wiki/subwiki2/view/Main/
Step 3: get your apache vhosts configuration correct.
Configurations, with only the bare minimum listed.
#/etc/apache/sites-enabled/111-wikiserver.conf
<VirtualHost wikiserver.example.com:80> ServerName wikiserver.example.com DocumentRoot /var/www/wikiserver <Location "/xwiki"> ProxyPreserveHost On ProxyPass http://127.0.0.1:8080/xwiki ProxyPassReverse http://127.0.0.1:8080/xwiki </Location> </VirtualHost>
#/etc/apache/sites-enabled/222-subwiki1.conf
<VirtualHost subwiki1.example.com:80> ServerName subwiki1.example.com DocumentRoot /var/www/subwiki1 <Location "/xwiki"> ProxyPreserveHost On ProxyPass http://127.0.0.1:8080/xwiki ProxyPassReverse http://127.0.0.1:8080/xwiki </Location> </VirtualHost>
#/etc/apache/sites-enabled/222-subwiki2.conf
<VirtualHost subwiki2.example.com:80> ServerName subwiki2.example.com DocumentRoot /var/www/subwiki2 <Location "/xwiki"> ProxyPreserveHost On ProxyPass http://127.0.0.1:8080/xwiki ProxyPassReverse http://127.0.0.1:8080/xwiki </Location> </VirtualHost>
Verify.
- http://wikiserver.example.com/xwiki
- http://subwiki1.example.com/xwiki/wiki/subwiki1/view/Main/
- http://subwiki2.example.com/xwiki/wiki/subwiki2/view/Main/
To make sure your vhosts are configured correctly, I dump an index.html file in the 3 DocumentRoot directories. The index.html file is a single line with only the text “<h1>[servername]</h1>” where [servername] is the domain name of the vhost. If I access http://servername/ and I get the right content back, then I know apache is configured properly.
Step 4: Configure tomcat/xwiki to use hostname based subwikis (reference here)
- edit /etc/xwiki/xwiki.properties and change url.standard.multiwiki.isPathBased to false (
url.standard.multiwiki.isPathBased=false) - edit /etc/xwiki/xwiki.cfg and change xwiki.virtual.usepath to 0 (
xwiki.virtual.usepath=0) - restart tomcat
- verify
And that should do it.
Keep in mind the following things:
- The following urls won’t work correctly after doing step 4. You’ll get an ugly error message. You can intercept that call and redirect it to the correct server if you wish, but I wouldn’t worry about it too much.
- configuring SSL is left as an exercise to the reader. I recommend using the “letsencrypt” software to manage the settings for you automatically with apache. You configure your http hosts and it will do the rest.
- tomcat has three ways to support connections from apache; via
- http
- ajp
- and mod_jk
Forget 3, as it is an old method.
If you use 1 (it’s simple and is easier to debug problems between apache and tomcat), then I suggest you bind Tomcat only to 127.0.0.1 to make sure not to expose your tomcat instance to the world. I only bind Tomcat to a public ip when I am testing things out. In the above example, we’re using this method.
The mod_ajp connection is a binary protocol that is supposedly more efficient to allow tomcat and apache to communicate. You can find the details in the /etc/tomcat9/server.xml. Search for AJP. You can then configure apache to proxy to ajp://127.0.0.1:8009/xwiki instead of http://127.0.0.1:8080/xwiki/.
When you have that working, you can disable Tomcats http connector.
Finally, adding a new wiki should be as simple as creating a new subwiki, and creating a new apache vhost configuration file with the details updated for the new subwiki name.
If anyone with more experience in this matter has any suggestions, corrections or updates, they are most welcome to share them. I only just tested this out now and while it seems to work, I may have missed something important.