You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Wildfly v32中简单虚拟主机配置失效问题排查

问题分析与解决方案

你的核心错误是用<file> handler直接指向WAR文件——Wildfly的file handler仅用于处理静态资源目录,无法识别已部署的WAR应用包。WAR文件部署后由Web容器管理,而非作为静态文件访问,这就是访问/url1时出现404并触发下载的原因。

正确的配置方案

方案1:修改WAR的上下文根(推荐)

直接让WAR应用绑定到/url1路径,同时保留原有/hello.war访问路径:

  1. 在你的hello.war的WEB-INF目录下创建jboss-web.xml文件
  2. 写入以下内容:
<jboss-web>
    <context-root>/url1</context-root>
</jboss-web>
  1. 重新部署WAR文件,此时localhost:8080/url1和localhost:8080/hello.war均可访问你的应用

方案2:用Rewrite规则实现多路径映射

如果需要保留原WAR的上下文根,同时添加/url1作为别名,可通过Wildfly的Rewrite子系统实现:

  1. 确保standalone.xml中已启用Rewrite扩展(默认已启用)
  2. 在<host>标签内添加Rewrite规则:
<host name="default-host" alias="localhost">
    <location name="/" handler="welcome-content"/>
    <location name="/url2" handler="welcome-content"/>
    <!-- 将/url1开头的请求转发到/hello.war -->
    <rewrite name="map-url1-to-hello" pattern="^/url1(.*)$" substitution="/hello.war$1" flags="L"/>
    <http-invoker http-authentication-factory="application-http-authentication"/>
</host>
  1. 重启Wildfly后,访问localhost:8080/url1会自动转发到你的hello.war应用

额外说明

你提到访问localhost:8080看到了hello world应用,这可能是因为WAR部署时意外覆盖了默认欢迎页配置。如果需要恢复默认欢迎页,确保/路径的handler保持为welcome-content,且没有额外的Rewrite规则或上下文根覆盖。

内容的提问来源于stack exchange,提问作者jdrew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 21:04:54