修改 tomcat/conf/server.xml,找到 engine 元素
<!-- default host is forbiden --> <Engine name="Catalina" defaultHost="forbiden"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> <!-- allow hosts --> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"></Host> <Host name="www.yourdomain.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"></Host> <Host name="192.168.1.3" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"></Host> <!-- forbiden host, the appBase is a not exists directory. If the requested domain is not in the above list of hosts where are allowed, then use this host. --> <Host name="forbiden" appBase="notexists" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"></Host> </Engine>
这里将 Engine 中的 defaultHost 设置为 forbiden,下面有个 name 为 forbiden 的 host,其 appBase 是个不存在的目录。再添加允许的 host。所以,如果是未知的域名,则会使用 forbiden 的 host,这样就访问不到真实应用目录了。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于