Liferay Symposium 2015 | Reserve your seat today.
« Back to Virtual Hosting...

Virtual Hosting (Communities)

Overview #

"Community Virtual Hosting" is an extension/variation of the "friendly URL" functionality of Liferay that allows one or more communities in a single portal instance to be identified by separate and unique "host names" (i.e. DNS entries). End users type in the name of the host they want to visit into the address bar in their browser, and while it APPEARS to the users that they are visiting different web sites, they are in fact being directed to a single web server (the Liferay server). The Liferay server determines which community to present to the user based on the "host name" being passed to it.

Setup #

The first step in using a virtual host to to ensure a Domain Name Server (DNS) entry exists for each virtual host you want, and that every one of them point to the IP address of your Liferay server. You must be familiar with DNS to get this feature to work. If you are not, see HowStuffWorks or WikiPedia. For testing purposes, you can set up test DNS entries on a local machine that maps a host name to the IP address of by editing the hosts file on your computer (in /etc/hosts in Linux/Unix, or \windows\system32\drivers\etc in MS Windows).

Next, be sure the com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter entry in the /portal/portal-ejb/classes/ file is set to "true" (this is the default).

Finally, log into your Liferay portal as the administrator. Ensure you have access to the "Communities" portlet. Locate the Community you are interested in mapping to the virtual host name in the Communities portlet, and click on the "Pages" icon. This will bring up the "Community Admin" page for the Community. Ensure the community name is the active node (i.e. the root node of the tree on the left), and then click on the "Virtual Host" tab. This is where you configure virtual hosts.

Each community has a "public" and a "private" area, thus each of these areas can have their own virtual host name. The "public community site" domain name must be different from the "private community site" domain name.

Virtual host names are optional. You can specify a name for the public site only, the private site only, or both.

Using Virtual Hosts #

Activating friendly url virtual hosting makes all of the following "public community" url's equivilant:


will now be the same as


Note you can still use the "fully qualified friendly URL" path. That is, this:


as well as


also still work.

Private community URLs are the same:


will now be the same as


Note you can still use the "fully qualified friendly URL" path. That is, this:


as well as


also still work.

So with virtual hosting enabled, you now have urls like this:


Removing /home From the URL #

To take this example one step further, its also often requested to remove the /home for the homepage:


to map to this:


To achieve this last step, put this in the .htaccess file in your top-level web directory.

# .htaccess in root of
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.public-virtualHostName\.com [NC]
RewriteRule ^(.*)$$1 [R=301,L]

RewriteRule ^/?$ /home [PT,L]
RewriteRule ^/home(.*) /$1 [R=301,L]

Step-by-Step Instructions #

Configuration In Liferay #

Log in to the Liferay as the administrator. ( is an administrator.

After signing in select the Open Communities Tab in the Communities portlet.

In it select the Community1 and click the “Configure Pages” Icon.

Under the Community1 we have created two pages “Community Page1” and “ca”

Now in the “Virtual Host” tab give the details mentioned below Public Virtual Host as Private Virtual Host as community1

And Friendly URL as /community1 This means instead of typing the url

http://localhost:8089/web/community1 we can map this entire URL with the

Configuration in the Host file #

In the path “C:\WINNT\system32\drivers\etc” open the host file and input the IP address from which Liferay is running, with the Virtual name associated with it in the Liferay.

The Virtual name is mapped with the IP address of the server in the conf file.

That’s it the configuration is over.

In Browser #

Type the URL as, note that you have to type the port number along with the URL , which will take you to the desired community means,

http://localhost:8089/web/community1 to

When the user types the above URL ( in the browser then this will take the user to the community directly, Liferay will take of the rest to take the user to the community page which the url is mapped

Since this is the Public page the User belongs to the community has to sign in to see the portlets.

User1 belongs to the community1 , so sign in

Since the user user1, belongs to the community1, since he signed in he can see all the potlets.

Using Apache, we are going to remove the Port number from the URL #

Put the file in the \modules folder in the apache home

Now open the folder conf in the Apache home and create a file named mod_jk2.conf

    <IfModule mod_jk2.c>
    # Where to find the file
    JkSet config.file

Put the above contents and save it.

Now create another file named and put the contents given below and save it

    info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
    # Defines a load balancer named lb. Use even if you only have one machine.
    # Example socket channel, override port and host.
    # define the worker
    ## Map the Tomcat examples webapp to the Web server uri space
    info=Status worker, displays runtime information
    info=The Tomcat /jkstatus handler

Now open the file httpd.conf include the below line

LoadModule jk2_module modules/

Start the Apache Server #

Now start the apache server in the Apache home bin folder

Apache is started

Now no need to type the full url like , now type only the . now no need to type the port number

Now the user can be taken directly to the Community1

Thus in Liferay we can have Virtual Hosting with different URL.

Examples #

An Enterprise Example #

Assume your company is named "Acme" and your normal portal domain is Also assume that the billing department has its own internal Community with the friendly URL of /billing.

You could set up a virtual host DNS entry in your company's DNS server to map to the same IP address as If you set up the virtual host in Liferay for the Billing department's private community to be, the following two URLs will get the user to that community:




Obviously, the first example is easier on the users.

An ASP example #

Assume you are a hosting company,, hosting web sites for different clients. One of your clients is has a public site (with shopping cart), as well as an intranet for its own employees and business partners to use.

Set up a community in your portal named "CoolStuff". For its public site, use the virtual host For the intranet, use something like,, or

Credits #

This functionality was a community contribution by Joel Kozikowski, thanks Joel!

0 Attachments
Average (1 Vote)
The average rating is 5.0 stars out of 5.
Threaded Replies Author Date
Hi there, one side note: When using Apache... Olaf Kock November 24, 2008 7:44 AM
Hi, I am trying to configure a virtual host... Phaneendra Vijay March 10, 2009 2:55 AM
Hi, Have you guys managed to resolve this? ... Ziggy © August 24, 2009 10:38 AM
Hi, Since it is behind the proxy, did you... Hermes Burg December 1, 2009 12:09 AM
Hi, I am trying to configure virtual host for... Cato Aune February 17, 2009 4:24 PM
Cato, Same for me. I am always redirected to... Martin Kofoed February 23, 2009 4:08 AM
Hi, in case others have the same problem, a... Cato Aune February 24, 2009 3:28 AM
Hi, How about enabling SSL? Is that possible... Hermes Burg December 1, 2009 12:16 AM
Hi Everybody, I have two virtual host: A and B... Vy Doan January 29, 2010 12:45 AM
Hi Everybody, I have two virtual host: A... Vy Doan January 29, 2010 12:46 AM
I created virtual host and all works fine... Jan E. E. Boen March 31, 2010 1:58 AM
Hi I have made changes some admin configuration... shoan david May 20, 2010 1:49 PM

Hi there,
one side note: When using Apache mod_jk without forwarding /* to tomcat (I'm usually using it to "JkMount" just some of the URLs, e.g. /web/*, /c/*, more portlets and themes) you'd have to "JkMount" all friendly (or unfriendly) urls that you define in your application.

This is a major drawback, as adding specific content may lead to the need to change your apache configuration (e.g. add another JkMount).

You've not written about JkMount here - I suppose that's handled by "JkSet". I'm not used to that, so my addition here may be pointless. On the other hand it might save some hairloss for people working with mod_jk (I've had major problems with this with my first setup)

I usually use (globally)
JkWorkersFile /path/to/
and in a VirtualHost directive
JkMount /path/* tomcat1

(Apologies if this answer is badly formatted - I'm missing some legal text descriptions for this answer box. Is it Wiki style? Forum style? Plain text?)
Posted on 11/24/08 7:44 AM.

I am trying to configure virtual host for a community in Liferay 5.2. Following this tutorial I get to my community if I use the URL
but if I just use
I am redirected to
and I see the homepage of the default organization.

Is it somehow possible to hide for the end users that it is a shared instance of Liferay as long as the end users are using the virtual hostname?


Posted on 2/17/09 4:24 PM.

Same for me. I am always redirected to the guest community pages no matter how I configure virtual hosting for my new community. I also tried configuring the site as an organization instead. Same problem.

I have MOD_JK forwarding all traffic to the Liferay instance on a glassfish server, and this works as expected. However, all requests end up the wrong place.

Anyone has any hints?
Posted on 2/23/09 4:08 AM in reply to Cato Aune.

in case others have the same problem, a solution is described in this forum thread:­e/2285386
Posted on 2/24/09 3:28 AM in reply to Martin Kofoed.

I am trying to configure a virtual host for the guest community in Liferay 5.1.2
I set the public virtual host to '' and left the private virtual host to blank, with the friendly URL as /guest.
Also I have changed the /windows/system32/drivers/etc/hosts file as
I am also behind a HTTP proxy.
Whenever I entered the in the url, I get the following error

The requested URL could not be retrieved

While trying to retrieve the URL:

The following error was encountered:

* Access Denied.

Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.
Posted on 3/10/09 2:55 AM in reply to Olaf Kock.

Have you guys managed to resolve this?

Posted on 8/24/09 10:38 AM in reply to Phaneendra Vijay.

Since it is behind the proxy, did you actually add the entry of into your Proxy Setting > Exceptions in your browser ?
Posted on 12/1/09 12:09 AM in reply to Phaneendra Vijay.

How about enabling SSL? Is that possible to have different SSL cert for different virtual host ?
Posted on 12/1/09 12:16 AM.
Hi Everybody,

I have two virtual host: A and B so how to configure or do more something to users belong to the host A can not login to host B.
Posted on 1/29/10 12:45 AM in reply to Hermes Burg.
Hi Everybody,

I have two virtual host: A and B so how to configure or do more something to users belong to the host A can not login to host B.
By default Liferay has one localhost in the company table.

Anyone can help me this.
Thanks very much.
Posted on 1/29/10 12:46 AM in reply to Hermes Burg.
I created virtual host and all works fine except for one little thing...
Once logged in the person has to manually switch to his correct community.
Any idea how this can be solved.
Btw... we're forced to still use LR4.2!!!
Posted on 3/31/10 1:58 AM.
I have made changes some admin configuration through the dock menu..
i changed in public virtual host settings .The 2 textboxes was blank earlier then i changed it '' in the public virtual host.and the private virtual host is left blank.after i made these changes , Now i cannot enter in to the site..i mean i can see the home page i could not login to the site, it says 500 server internal error.

Can you tell me..

These changes will reflect only in liferay tomcat only or configuration in linux server files. i replaced it with the back up files. The things are the same.

Please tell me where i need to change to get rid of this issue... your help would be appreciated

Thanks in advance

Posted on 5/20/10 1:49 PM in reply to Jan E. E. Boen.