I want to map a domain mydomain.com
to an application. I added a <Host>
entry into server.xml
, but when I go to www.mydomain.com
it shows the Tomcat start page instead of my application.
server.xml:
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" autoDeploy="true" unpackWARs="true" appBase="webapps">
<Valve className="org.apache.catalina.valves.AccessLogValve" pattern="%h %l %u %t "%r" %s %b" suffix=".txt" prefix="localhost_access_log" directory="logs"/>
</Host>
<Host name="mydomain.com" autoDeploy="true" unpackWARs="true" appBase="webapps">
<Alias>www.mydomain.com</Alias>
<Context privileged="true" debug="0" docBase="/opt/tomcat/webapps/MyDomain" path=""/>
<Valve className="org.apache.catalina.valves.AccessLogValve" pattern="%h %l %u %t "%r" %s %b" suffix=".txt" prefix="localhost_access_log." directory="logs" resolveHosts="false"/>
</Host>
</Engine>
Thanks in advance!
You have defined two hosts with the same deployment directory webapps
If you want localhost
to be different than mydomain
define two deployment directories and rename the root context war to ROOT.war. it is not recommended to use <Context
tag
<Host name="localhost" autoDeploy="true" unpackWARs="true" appBase="webapps">
<Host name="www.mydomain.com" autoDeploy="true" unpackWARs="true" appBase="mydomain">
</Host>
You do not need alias
since the host name contains the domain name. All others requests coming from a DNS entry different to www.domain.com
will be served by localhost
If localhost
and www.domain.com
are the same, then you just need a <Host
and deploy a ROOT.war
<Host name="localhost" autoDeploy="true" unpackWARs="true" appBase="webapps">
</Host>
What worked for me was to map my applications like this in the server.xml file.
Delete the host entry you added and inside the host entry you had from the start put this:
<Context path="/" docBase="yourApp">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="/ROOT" docBase="ROOT">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
Dont forget to change yourApp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.