本文介绍LINUX服务器使用tomcat绑定单域名,且直接输入域名即访问到制定项目,例如输入www.xxx.com访问到名字为test的项目
共分三步,
第一步,配置ip
vi /etc/hosts
加入一行127.0.0.1 www.xxx.com
第二步,配置tomcat的server.xml文件
vi ${catalina_home}/conf/server.xml (就是你tomcat安装目录下的conf文件下的server.xml文件)
这里粘出需要修改的部分,红色字体为修改的内容
<Engine name="Catalina" defaultHost="www.xxx.com">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="www.xxx.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
<Context path="" docBase="$CATALINA_HOME/webapps/test" reloadable="true" crossContext="true"/>
</Host>
</Engine>
第三步,删除ROOT目录
因为不删除ROOT目录不会访问到我们配置的项目
很多人没有配置成功就是因为没有删除该目录
cd $CATALINA_HOME/webapps
rm -R -f ROOT
启动tomcat试试吧