Tomcat Virtual hosting in Linux
Tomcat Virtual hosting in Unix
The tomcat virtual hosting configuration in Unix/Linux is simple.
1) Create the virtual host entry in server.xml
2) Create the document root
3) Restart tomcat
let us consider the tomcat installation root is /usr/local/tomcat
To start the tomcat use /usr/local/tomcat/bin/start.sh
To stop the tomcat use /usr/loca/tomcat/bin/shutdown.sh
The following is my server.xml. Please copy paste and change the domain.com
====================================
# more conf/server.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<Server>
<Listener className=”org.apache.catalina.core.AprLifecycleListener”/>
<Listener className=”org.apache.catalina.mbeans.GlobalResourcesLifecycleListener”/>
<Listener className=”org.apache.catalina.storeconfig.StoreConfigLifecycleListener”/>
<Listener className=”org.apache.catalina.mbeans.ServerLifecycleListener”/>
<GlobalNamingResources>
<Environment
name=”simpleValue”
type=”java.lang.Integer”
value=”30″/>
<Resource
auth=”Container”
description=”User database that can be updated and saved”
name=”UserDatabase”
type=”org.apache.catalina.UserDatabase”
pathname=”conf/tomcat-users.xml”
factory=”org.apache.catalina.users.MemoryUserDatabaseFactory”/>
</GlobalNamingResources>
<Service
name=”Catalina”>
<Connector
port=”80″
redirectPort=”8443″
minSpareThreads=”25″
connectionTimeout=”20000″
maxSpareThreads=”75″
maxThreads=”150″>
</Connector>
<Connector
port=”8009″
redirectPort=”8443″
protocol=”AJP/1.3″>
</Connector>
<Engine
defaultHost=”localhost”
name=”Catalina”>
<Realm className=”org.apache.catalina.realm.UserDatabaseRealm”/>
<Host
appBase=”mydomain”
name=”mydomain.com”>
<Context path=”” docBase=”.”/>
<Alias>www.mydomain.com</Alias>
</Host>
<Host
appBase=”webapps”
name=”localhost”>
</Host>
</Engine>
</Service>
</Server>
============================
Now create the document root “/usr/local/tomcat/mydomain” and directory structure as follows
# mkdir -p /usr/local/tomcat/mydomain/{WEB-INF/{classes,lib},META-INF}
Create a test index.jsp file in here ,
# cat > /usr/local/tomcat/mydomain/index.jsp << EOF
<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>Centropoly</title>
</head>
<body>
<h2>Welcome to the temporary home of mydomain.com.</h2>
<p>
Just for testing
</p>
</body>
</html>
EOF
This is all about simple virtual hosting in tomcat. I testes the above configuration successfully in Tomcat 5
Any comments