Serving multiple sites
This module describes how you can make your OpenCms server to be a CMS for several sites.
Please note: Make sure that all your server names are correctly configured in your DNS before you continue with this installation. If a server can not be reached with the name(s) used in the configuration files below, the setup will not work.
I will describe the required steps to setup the following scenario:
- The OpenCms editor server (where the pages are edited by the content managers) is named opencms.alkacon.com
- One virtual server named www.siteA.com is to serve all files in the /sites/siteA/ directory and below
- Another virtual server named siteB.org is to serve all files in the /sites/siteB/ directory and below
- All three virtual servers will be served from a Tomcat installation located in the directory C:\Java\Tomcat5\
This scenario assumes that the static ressources are served by an Apache server which runs on the same machine (server hardware). For details of how to set up such a system, see the com.alkacon.documentation.howto_apache_httpd documentation module. Further, we assume, that the /opencms/opencms/ prefix usually required for OpenCms will be supressed, which is also documented in the documentation mentioned before. This procedure also works, if you want to use the Tomcat server both for static and dynamic content. Again, you must adjust the names of the server to your environment, and also adjust other variables like the ServerAdmin or the DocumentRoot to match your system.
Step 1: Configuring Tomcat
The Tomcat server, you have to configure in the file {$TOMCAT_HOME}/conf/server.xml
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
proxyName="opencms.alkacon.com" proxyPort="80"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />
<Connector port="8081"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
proxyName="www.siteA.com" proxyPort="80"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />
<Connector port="8082"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
proxyName="siteB.org" proxyPort="80"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />
Step 2: Configuring httpd
In the You need to add the following <VirtualHost> container directives
<VirtualHost *:80>
ServerName opencms.alkacon.com
ServerAdmin webmaster@alkacon.com
DocumentRoot "C:/Java/Tomcat5/webapps/ROOT/"
ErrorLog logs/error.log
# Log only non-redirect requests in "normal" log file
SetEnvIf Request_URI "\/opencms\/*" redirect
CustomLog logs/localhost-access.log common env=!redirect
ProxyPass /opencms/ !
RedirectPermanent /opencms/ http://opencms.alkacon.com/
ProxyPass /resources/ !
ProxyPass /export/ !
ProxyPass / http://127.0.0.1:8080/opencms/
ProxyPassReverse / http://127.0.0.1:8080/opencms/
</VirtualHost>
<VirtualHost *:80>
ServerName www.siteA.com
ServerAdmin webmaster@siteA.com
DocumentRoot "C:/Java/Tomcat5/webapps/ROOT/"
ErrorLog logs/error.log
# Log only non-redirect requests in "normal" log file
SetEnvIf Request_URI "\/opencms\/*" redirect
CustomLog logs/siteA-access.log common env=!redirect
# Multi domain configuration: All pages in "/siteA/" are to be served from domain "www.siteA.com"
ProxyPass /opencms/ !
RedirectPermanent /opencms/ http://www.siteA.com
ProxyPass /resources/ !
ProxyPass /export/ !
ProxyPass / http://127.0.0.1:8081/opencms/
ProxyPassReverse / http://127.0.0.1:8081/opencms/
</VirtualHost>
<VirtualHost *:80>
ServerName siteB.org
ServerAdmin webmaster@siteB.org
DocumentRoot "C:/Java/Tomcat5/webapps/ROOT/"
ErrorLog logs/error.log
# Log only non-redirect requests in "normal" log file
SetEnvIf Request_URI "\/opencms\/*" redirect
CustomLog logs/siteB-access.log common env=!redirect
# Multi domain configuration: All pages in "/siteB/" are to be served from domain "siteB.org"
ProxyPass /opencms/ !
RedirectPermanent /opencms/ http://siteB.org/
ProxyPass /resources/ !
ProxyPass /export/ !
ProxyPass / http://127.0.0.1:8082/opencms/
ProxyPassReverse / http://127.0.0.1:8082/opencms/
</VirtualHost>
Step 3: Configuring OpenCms
Now, open the OpenCms configuration file {$TOMCAT_HOME}/webapps/ROOT/WEB-INF/config/opencms-system.xml. Locate the sites node and add for each site a node. In our example, after editing, it has to look similar to:
<sites>
<workplace-server>http://localhost:8080</workplace-server>
<default-uri>/sites/default/</default-uri>
<site server="opencms.alkacon.com" uri="/sites/default/"/>
<site server="www.siteA.com" uri="/sites/siteA/"/>
<site server="siteB.org" uri= "/sites/siteB/"/>
</sites>
Now, it should work.