Configure two websites in the same instance in Liferay 7

Configure two websites in the same instance in Liferay 7

One of the most common configurations we want to apply in Liferay is to serve two or more websites with the same Liferay instance. However, configuring Liferay in the right way to serve our websites and generate the links properly is not an easy and immediate task.

This guide contains a set of steps you can follow in order to configure two websites in the same Liferay instance. We are supposing you have a regular Liferay configuration with these points:

  • Tomcat is serving Liferay in the port 8080
  • Apache is getting the HTTPS client’s requests (port 443)

Step 1. Configure Virtual Hosts in Apache

A virtual host configuration for (Apache)

This is an example of a virtual host configuration file compatible with Apache. This configuration needs the mod_proxy and mod_ssl enabled.

<IfModule mod_ssl.c>
	<VirtualHost _default_:443>
		# Your server name should be set here

		DocumentRoot /var/www/html

		ErrorLog ${APACHE_LOG_DIR}/
		CustomLog ${APACHE_LOG_DIR}/ combined

		# We turn SSL Engine on
		SSLEngine on
        SSLProtocol -ALL +TLSv1 +TLSv1.1 +TLSv1.2

        # We provide the certificates
		SSLCertificateFile	/path/to/ssl/certs/
        SSLCertificateChainFile /path/to/ssl/certs/ca.crt
		SSLCertificateKeyFile /path/to/ssl/certs/

		<FilesMatch "\.(cgi|shtml|phtml|php)$">
				SSLOptions +StdEnvVars

		# This allows or prevents Apache httpd from functioning as a forward proxy server. (Setting ProxyRequests to Off does not disable use of the ProxyPass directive.)
		# In a typical reverse proxy or gateway configuration, this option should be set to Off.
		ProxyRequests Off

		# We configure our mod_proxy module (including the reverse proxy)
		# This line is VERY important, since it will allow us to pass the Host: line from the incoming request to the proxied host, 
		# instead of the hostname specified in the ProxyPass line
        ProxyPreserveHost On
        ProxyTimeout 300

        # This directive allows remote servers to be mapped into the space of the local server. The local server does not act as a proxy in the conventional sense but appears to be a mirror of the remote server. 
        # The local server is often called a reverse proxy or gateway. 
        ProxyPass        /

		# This directive lets Apache httpd adjust the URL in the Location, Content-Location and URI headers on HTTP redirect responses. 
		# This is essential when Apache httpd is used as a reverse proxy (or gateway) to avoid bypassing the reverse proxy because of HTTP redirects on the backend servers 
		# which stay behind the reverse proxy.
        ProxyPassReverse /


A virtual host configuration for (Apache)

Repeat the previous configuration just replacing the “” configuration by “”.

Step 2. Configure Proxy Connector in Tomcat

Following is a fragment of the server.xml file available in a path similar to /path/to/liferay/tomcat/conf/server.xml

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN" address="">
  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
  <Service name="Catalina">
    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    <Connector port="8080" address="" protocol="HTTP/1.1"
               redirectPort="8443" URIEncoding="UTF-8"

The important part of the previous file is the <Connector />. Please, be aware we ARE NOT setting the proxyName which could be configured to one valid domain like

Caution. Following configuration is NOT going to work since we are setting the proxyName which will modify the Host request header.
<Connector port="8080" address="" protocol="HTTP/1.1"
               redirectPort="8443" URIEncoding="UTF-8"
Correct. Now, if we remove the proxyName, our Liferay websites would be ready to keep the Host request header and generate the links as expected.
<Connector port="8080" address="" protocol="HTTP/1.1"
               redirectPort="8443" URIEncoding="UTF-8"

Step 3. Configure Virtual Hosts for Public / Private Pages in Liferay

Go to Your Site > Site Settings > General > Site URL and configure your “Friendly URL”, “Public Pages” and “Private Pages”. Notice this last “Private Pages” is empty to Liferay can autogenerate the URLs.

This process needs to be repeated for both “”, “” and any other domain you want to configure in the same Liferay instance.

That’s it! From now on, your Liferay instance is going to be able to serve many sites with custom domains.

See you next time!

Best regards.

  • Prev Post
  • Next Post