我正在尝试在 Tomcat 8.5.9 上设置多个子域,但我无法在 server.xml 中获得正确的语法以使其正常工作。我确信这是我最后遗漏的东西,但我发现没有一篇文章在不使用 Apache 的情况下给出了完整的解释。我在这里没有使用 Apache 或 NGINX。我只想设置一个 DEV 服务器,其中包含托管在同一 JVM 上的多个子域。
test.foo.com
test1.foo.com
DNS 设置正确,每个 URL 的 nslookup 都提供相同的公共(public) IP 地址。
应用程序被部署到“webapps”的“test”和“test1”目录。
这种设置 test1.foo.com URL 的方式有效,但是当我点击 test.foo.com URL 时出现 404 错误。错误正在写入日志,因此它正在出现。
这些是我在 server.xml 中的主机条目:
<Host name="test.foo.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="test" path=""/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="test_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="test1.foo.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="test1" path=""/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="author_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
如果有人能看到任何错误,我将不胜感激。
最佳答案
(在评论中解决)
在appBase
中为每个虚拟主机设置不同的目录。 general documentation不建立限制,但具体documentation for virtual host说你不能为两个虚拟主机使用相同的目录
Note that the directory structures under the appBase for each host should not overlap each other.
关于java - Tomcat 8.5.9 多个子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41794272/