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 127.0.0.1 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/system.properties 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.
Activating friendly url virtual hosting makes all of the following "public community" url's equivilant:
**www.public-virtualHostName.com/somePage**
will now be the same as
**www.defaultServerName.com/web///communityURL///somePage**
Note you can still use the "fully qualified friendly URL" path. That is, this:
**www.defaultServerName.com/web///communityURL///somePage**
as well as
**www.public-virtualHostName.com/web///communityURL///somePage**
also still work.
Private community URLs are the same:
**www.private-virtualHostName.com/somePage**
will now be the same as
**www.defaultServerName.com/group///communityURL///somePage**
Note you can still use the "fully qualified friendly URL" path. That is, this:
**www.defaultServerName.com/group///communityURL///somePage**
as well as
**www.private-virtualHostName.com/group///communityURL///somePage**
also still work.
So with virtual hosting enabled, you now have urls like this:
**www.public-virtualHostName.com/home **www.public-virtualHostName.com/test **www.public-virtualHostName.com/contact **www.public-virtualHostName.com/foo
To take this example one step further, its also often requested to remove the /home for the homepage:
**www.public-virtualHostName.com
to map to this:
**www.public-virtualHostName.com/home
To achieve this last step, put this in the .htaccess file in your top-level web directory.
# .htaccess in root of www.public-virtualHostName.com
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.public-virtualHostName\.com [NC]
RewriteRule ^(.*)$ [http://www.public-virtualHostName.com]$1 [R=301,L]
RewriteRule ^/?$ /home [PT,L]
RewriteRule ^/home(.*) /$1 [R=301,L]
Log in to the Liferay as the administrator. (Mani@liferay.com) 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 www.community1.com 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 www.community1.com
![]() |
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 www.community1.com is mapped with the IP address of the server in the conf file.
That’s it the configuration is over.
Type the URL as http://www.community1.com:8089, 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 http://www.community1.com:8089
![]() |
When the user types the above URL (http://www.community1.com:8089) 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.
![]() |
Put the mod_jk2.so 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 workers2.properties file
#-----------------------------------------------
#
JkSet config.file workers2.properties
</IfModule>
Put the above contents and save it.
Now create another file named workers2.properties and put the contents given below and save it
#-----------------------------------------------
[shm]
info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
file=anon
# Defines a load balancer named lb. Use even if you only have one machine.
#[lb:lb]
# Example socket channel, override port and host.
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1
# define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
group=lb
## Map the Tomcat examples webapp to the Web server uri space
[uri:www.community1.com/*]
[uri:www.community2.com/*]
[uri:www.community3.com/*]
group=lb
[status:]
info=Status worker, displays runtime information
[uri:/jkstatus/*]
info=The Tomcat /jkstatus handler
###group=status:
#-----------------------------------------------
Now open the file httpd.conf include the below line
LoadModule jk2_module modules/mod_jk2.so
![]() |
Now start the apache server in the Apache home bin folder
![]() |
Apache is started
![]() |
Now no need to type the full url like http://www.community1.com:8089 , now type only the http://www.community1.com . 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.
Assume your company is named "Acme" and your normal portal domain is www.acme.com. 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 billing.acme.com to the same IP address as www.acme.com. If you set up the virtual host in Liferay for the Billing department's private community to be billing.acme.com, the following two URLs will get the user to that community:
**billing.acme.com**
and/or
**www.acme.com/group/billing**
Obviously, the first example is easier on the users.
Assume you are a hosting company, www.hostings-r-us.com, hosting web sites for different clients. One of your clients is CoolStuff.com. CoolStuff.com 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 www.hostings-r-us.com portal named "CoolStuff". For its public site, use the virtual host www.coolstuff.com. For the intranet, use something like internal.coolstuff.com, admin.coolstuff.com, or staff.coolstuff.com.
This functionality was a community contribution by Joel Kozikowski, thanks Joel!
0 Attachments | Average (1 Vote) ![]() ![]() ![]() ![]() |