直接记录自己的server.xml代码:
以下代码配置后可以通过ip+8080访问:
<Server port="-1" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
address="0.0.0.0"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"
/>
<Connector port="8080" protocol="AJP/1.3"
address="0.0.0.0"
redirectPort="8443"
URIEncoding="UTF-8"
/>
<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="121.5.227.176" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\webapps\ROOT" reloadable="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
设置直接通过ip访问(不需要端口号)
我先是在网站绑定当中删除80端口
然后
<Connector port="80" protocol="HTTP/1.1"
address="0.0.0.0"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"
/>
<Connector port="80" protocol="AJP/1.3"
address="0.0.0.0"
redirectPort="8443"
URIEncoding="UTF-8"
/>
<Engine name="Catalina" defaultHost="121.5.227.176">
<!--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="121.5.227.176" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\webapps\ROOT" reloadable="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" />
</Host>
</Engine>
另外看了很多帖子好像都是在eclipse里面打开tomcat,我没有用eclipse打开,直接是安装了tomcat9,然后把static和index.html粘贴到webapps下面,然后那个</context 的配置我也不知道是咋回事,好像很多帖子是有项目名,但是我的貌似没有项目名