4.5. Web 服务器配置更改


4.5.1. 将 Web 子系统替换为 Undertow

Undertow 取代 JBoss Web 作为 JBoss EAP 7 中的 Web 服务器。这意味着旧版 Web 子系统配置必须迁移到新的 JBoss EAP 7 undertow 子系统配置。

  • 服务器配置文件中的 urn:jboss:domain:web:2.2 子系统配置命名空间已被 urn:jboss:domain:undertow:10.0 命名空间取代。
  • EAP_HOME/modules/system/layers/base/ 中的 org.jboss.as.web 扩展模块已被 org.wildfly.extension.undertow 扩展模块取代。

您可以使用管理 CLI migrate 操作,将 Web 子系统迁移到服务器配置文件中的 undertow。但是,请注意,此操作无法迁移所有 JBoss Web 子系统配置。如果您看到"migration-warning"条目,则必须运行其他管理 CLI 命令将这些配置迁移到 Undertow。如需有关管理 CLI migrate 操作的更多信息,请参阅管理 CLI 迁移操作

以下是 JBoss EAP 6.4 中默认 Web 子系统配置的示例:

<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <virtual-server name="default-host" enable-welcome-root="true">
        <alias name="localhost"/>
        <alias name="example.com"/>
    </virtual-server>
</subsystem>
Copy to Clipboard Toggle word wrap

以下是 JBoss EAP 7.4 中默认 undertow 子系统配置的示例:

<subsystem xmlns="urn:jboss:domain:undertow:10.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other">
    <buffer-cache name="default"/>
    <server name="default-server">
        <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
        <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
        <host name="default-host" alias="localhost">
            <location name="/" handler="welcome-content"/>
            <http-invoker security-realm="ApplicationRealm"/>
        </host>
    </server>
    ...
</subsystem>
Copy to Clipboard Toggle word wrap

4.5.2. 迁移 JBoss Web 重写条件

管理 CLI migrate 操作无法自动迁移重写条件。它们报告为"迁移警告",您必须手动迁移。您可以使用 Undertow Predicates Attributes and Handlers 在 JBoss EAP 7 中创建等效的配置。

以下是包含 rewrite 配置的 JBoss EAP 6 中的 web 子系统配置示例:

<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default" native="false">
    <virtual-server name="default" enable-welcome-root="true">
        <alias name="localhost"/>
        <rewrite name="test" pattern="(.*)/toberewritten/(.*)" substitution="$1/rewritten/$2" flags="NC"/>
        <rewrite name="test2" pattern="(.*)" substitution="-" flags="F">
            <condition name="get" test="%{REQUEST_METHOD}" pattern="GET"/>
            <condition name="andCond" test="%{REQUEST_URI}" pattern=".*index.html" flags="NC"/>
        </rewrite>
    </virtual-server>
</subsystem>
Copy to Clipboard Toggle word wrap

按照 管理 CLI 迁移操作 说明启动您的服务器和管理 CLI,然后使用以下命令迁移 web 子系统配置文件:

/subsystem=web:migrate
Copy to Clipboard Toggle word wrap

当您在上述配置上运行 web 操作时,将报告以下"migration-warnings"。

/subsystem=web:migrate
{
    "outcome" => "success",
    "result" => {"migration-warnings" => [
        "WFLYWEB0002: Could not migrate resource {
    \"pattern\" => \"(.*)\",
    \"substitution\" => \"-\",
    \"flags\" => \"F\",
    \"operation\" => \"add\",
    \"address\" => [
        (\"subsystem\" => \"web\"),
        (\"virtual-server\" => \"default-host\"),
        (\"rewrite\" => \"test2\")
    ]
}",
        "WFLYWEB0002: Could not migrate resource {
    \"test\" => \"%{REQUEST_METHOD}\",
    \"pattern\" => \"GET\",
    \"flags\" => undefined,
    \"operation\" => \"add\",
    \"address\" => [
        (\"subsystem\" => \"web\"),
        (\"virtual-server\" => \"default-host\"),
        (\"rewrite\" => \"test2\"),
        (\"condition\" => \"get\")
    ]
}",
        "WFLYWEB0002: Could not migrate resource {
    \"test\" => \"%{REQUEST_URI}\",
    \"pattern\" => \".*index.html\",
    \"flags\" => \"NC\",
    \"operation\" => \"add\",
    \"address\" => [
        (\"subsystem\" => \"web\"),
        (\"virtual-server\" => \"default-host\"),
        (\"rewrite\" => \"test2\"),
        (\"condition\" => \"andCond\")
    ]
}"
    ]}
}
Copy to Clipboard Toggle word wrap

检查服务器配置文件,并且您看到 undertow 子系统的以下配置:

注意

重写配置已被丢弃。

<subsystem xmlns="urn:jboss:domain:undertow:10.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other">
     <buffer-cache name="default"/>
     <server name="default-server">
         <http-listener name="http" socket-binding="http"/>
         <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
         <host name="default-host" alias="localhost, example.com">
             <location name="/" handler="welcome-content"/>
         </host>
     </server>
     <servlet-container name="default">
         <jsp-config/>
     </servlet-container>
     <handlers>
         <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
     </handlers>
 </subsystem>
Copy to Clipboard Toggle word wrap

使用管理 CLI 创建过滤器,以取代 undertow 子系统中的重写配置。对于每个命令,您应该可以看到 "{"outcome" SAS "success"}"。

# Create the filters
/subsystem=undertow/configuration=filter/expression-filter="test1":add(expression="path('(.*)/toberewritten/(.*)') -> rewrite('$1/rewritten/$2')")
/subsystem=undertow/configuration=filter/expression-filter="test2":add(expression="method('GET') and path('.*index.html') -> response-code(403)")

# Add the filters to the default server
/subsystem=undertow/server=default-server/host=default-host/filter-ref="test1":add
/subsystem=undertow/server=default-server/host=default-host/filter-ref="test2":add
Copy to Clipboard Toggle word wrap

检查更新的服务器配置文件。JBoss Web 子系统现已完全在 undertow 子系统中进行迁移和配置。

<subsystem xmlns="urn:jboss:domain:undertow:10.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other">
    <buffer-cache name="default"/>
    <server name="default-server">
        <http-listener name="http" socket-binding="http"/>
        <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
        <host name="default-host" alias="localhost, example.com">
            <location name="/" handler="welcome-content"/>
            <filter-ref name="test1"/>
            <filter-ref name="test2"/>
        </host>
    </server>
    <servlet-container name="default">
        <jsp-config/>
    </servlet-container>
    <handlers>
        <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    </handlers>
    <filters>
        <expression-filter name="test1" expression="path('(.*)/toberewritten/(.*)') -> rewrite('$1/rewritten/$2')"/>
        <expression-filter name="test2" expression="method('GET') and path('.*index.html') -> response-code(403)"/>
    </filters>
</subsystem>
Copy to Clipboard Toggle word wrap

有关如何使用管理 CLI 配置过滤器和处理程序的更多信息,请参阅 JBoss EAP 7 配置指南中的配置 Web 服务器

4.5.3. 迁移 JBoss Web 系统属性

在之前的 JBoss EAP 版本中,系统属性可用于修改默认的 JBoss Web 行为。有关如何在 Undertow 中配置相同行为的详情,请查看 JBoss Web 系统属性迁移参考

4.5.4. 更新 Access Log Header Pattern

从 JBoss EAP 6.4 迁移到 JBoss EAP 7 时,您可能会发现访问日志不再编写预期的"Referer"和"User-agent"值。这是因为 JBoss EAP 6.4 中包含的 JBoss Web 使用 access-log 中的 %{headername}i 模式来记录传入的标头。

示例:访问 JBoss EAP 6.4 中的日志格式

<access-log pattern="%h %l %u %t &quot;%T sec&quot; &quot;%r&quot; %s %b &quot;%{Referer}i&quot; &quot;%{User-agent}i&quot;"/>
Copy to Clipboard Toggle word wrap

随着在 JBoss EAP 7 中使用 Undertow 的更改,传入标头的模式已更改为 %{i,headername}

示例:JBoss EAP 7 中的访问格式标头

<access-log pattern="%h %l %u %t &quot;%T sec&quot; &quot;%r&quot; %s %b &quot;%{i,Referer}&quot; &quot;%{i,User-Agent}&quot;"/>
Copy to Clipboard Toggle word wrap

4.5.5. 迁移 Global Valves

以前 JBoss EAP 版本支持的 valves。valves 是插入到应用的请求处理管道中的自定义类,在 servlet 过滤器之前插入,以更改请求或执行其他处理。

  • 全局 valves 会被插入到所有部署的应用的请求处理管道中,并在服务器配置文件中配置。
  • 身份验证器 valves 验证请求的凭据。
  • 通过扩展 org.apache.catalina.valves.ValveBase 类并配置在 jboss-web.xml 描述符文件的 <valve> 元素中创建自定义应用程序 valves。这些 valve 必须手动迁移。

本节论述了如何迁移全局 valves。本指南的迁移自定义应用程序 Valves 一节介绍了自定义和验证器的迁移。

Undertow(在 JBoss EAP 7 中取代 JBoss Web)不支持全局 valves;但是,您应该能够通过使用 Undertow 处理程序来实现类似的功能。Undertow 包含多个提供常见功能的内置处理程序:它还提供创建自定义处理程序的功能,可用于取代自定义 valve 功能。

如果您的应用使用 valves,则必须将它们替换为适当的 Undertow 处理程序代码,以便在迁移到 JBoss EAP 7 时获得相同的功能。

如需有关如何配置处理程序的更多信息,请参阅 JBoss EAP 7 配置指南中的配置处理程序

如需有关如何配置过滤器的更多信息,请参阅 JBoss EAP 7 配置指南中的配置过滤器

迁移 JBoss Web Valves

下表列出了 JBoss EAP 之前版本中 JBoss Web 提供的 valves,以及对应的 Undertow 内置处理程序:JBoss Web valves 位于 org.apache.catalina.valves 包中。

Expand
表 4.2. 将 Valves 映射到处理程序
Valve处理程序

AccessLogValve

io.undertow.server.handlers.accesslog.AccessLogHandler

CrawlerSessionManagerValve

io.undertow.servlet.handlers.CrawlerSessionManagerHandler

ExtendedAccessLogValve

io.undertow.server.handlers.accesslog.AccessLogHandler

JDBCAccessLogValve

相关说明请查看下面的 JDBCAccessLogValve 手动迁移过程

RemoteAddrValve

io.undertow.server.handlers.IPAddressAccessControlHandler

RemoteHostValve

io.undertow.server.handlers.AccessControlListHandler

RemoteIpValve

io.undertow.server.handlers.ProxyPeerAddressHandler

RequestDumperValve

io.undertow.server.handlers.RequestDumpingHandler

RewriteValve

有关手动迁移这些 valve 的说明,请参阅迁移 JBoss Web 重写条件

StuckThreadDetectionValve

io.undertow.server.handlers.StuckThreadDetectionHandler

您可以使用管理 CLI migrate 操作自动迁移满足以下条件的全局 valves:

  • 它们仅限于上表中列出的 valve,不需要手动处理。
  • 它们必须在服务器配置文件的 Web 子系统中定义。

如需有关管理 CLI migrate 操作的更多信息,请参阅管理 CLI 迁移操作

JDBCAccessLogValve 手工迁移过程

org.apache.catalina.valves.JDBCAccessLogValve valve 是规则的例外,无法自动迁移到 io.undertow.server.handlers.JDBCLogHandler。按照以下步骤迁移以下示例 valve。

<valve name="jdbc" module="org.jboss.as.web" class-name="org.apache.catalina.valves.JDBCAccessLogValve">
    <param param-name="driverName" param-value="com.mysql.jdbc.Driver" />
    <param param-name="connectionName" param-value="root" />
    <param param-name="connectionPassword" param-value="password" />
    <param param-name="connectionURL" param-value="jdbc:mysql://localhost:3306/wildfly?zeroDateTimeBehavior=convertToNull" />
    <param param-name="format" param-value="combined" />
</valve>
Copy to Clipboard Toggle word wrap
  1. 为数据库创建一个驱动程序模块,它将存储日志条目。
  2. 配置数据库的数据源,并将驱动程序添加到 datasources 子系统中可用驱动程序的列表中。

    <datasources>
        <datasource jndi-name="java:jboss/datasources/accessLogDS" pool-name="accessLogDS" enabled="true" use-java-context="true">
            <connection-url>jdbc:mysql://localhost:3306/wildfly?zeroDateTimeBehavior=convertToNull</connection-url>
            <driver>mysql</driver>
            <security>
               <user-name>root</user-name>
               <password>Password1!</password>
            </security>
        </datasource>
        ...
        <drivers>
            <driver name="mysql" module="com.mysql">
                <driver-class>com.mysql.jdbc.Driver</driver-class>
            </driver>
        ...
        </drivers>
    </datasources>
    Copy to Clipboard Toggle word wrap
  3. undertow 子系统中,使用以下表达式配置 expression-filterjdbc-access-log(datasource=DATASOURCE_JNDI_NAME)

    <filters>
        <expression-filter name="jdbc-access" expression="jdbc-access-log(datasource='java:jboss/datasources/accessLogDS')" />
        ...
    </filters>
    Copy to Clipboard Toggle word wrap

4.5.7. 更改 HTTP 方法调用行为

JBoss EAP 6.4(包括 JBoss Web 作为 Web 服务器)默认允许 HTTP TRACE 方法调用。

Undertow(替换 JBoss Web 作为 JBoss EAP 7 中的 Web 服务器)默认不允许 HTTP TRACE 方法调用。此设置使用 undertow 子系统中 http-listener 元素的 disallowed-methods 属性进行配置。可以通过查看以下 read-resource 命令的输出来确认这一点。注意 disallowed-methods 属性的值为 ["TRACE"]

/subsystem=undertow/server=default-server/http-listener=default:read-resource
{
    "outcome" => "success",
    "result" => {
        "allow-encoded-slash" => false,
        "allow-equals-in-cookie-value" => false,
        "allow-unescaped-characters-in-url" => false,
        "always-set-keep-alive" => true,
        "buffer-pipelined-data" => false,
        "buffer-pool" => "default",
        "certificate-forwarding" => false,
        "decode-url" => true,
        "disallowed-methods" => ["TRACE"],
         ...
    }
}
Copy to Clipboard Toggle word wrap

若要在 JBoss EAP 7 及更高版本中启用 HTTP TRACE 方法调用,您必须运行以下命令,从 disallowed-methods 属性列表中删除"TRACE"条目:

/subsystem=undertow/server=default-server/http-listener=default:list-remove(name=disallowed-methods,value="TRACE")
Copy to Clipboard Toggle word wrap

当再次运行 read-resource 命令时,您会注意到 TRACE 方法调用不再在禁止的方法列表中。

/subsystem=undertow/server=default-server/http-listener=default:read-resource
{
    "outcome" => "success",
    "result" => {
        "allow-encoded-slash" => false,
        "allow-equals-in-cookie-value" => false,
        "allow-unescaped-characters-in-url" => false,
        "always-set-keep-alive" => true,
        "buffer-pipelined-data" => false,
        "buffer-pool" => "default",
        "certificate-forwarding" => false,
        "decode-url" => true,
        "disallowed-methods" => [],
         ...
    }
}
Copy to Clipboard Toggle word wrap

如需有关 HTTP 方法默认行为的更多信息,请参阅 JBoss EAP 配置指南中的 HTTP 方法默认行为

4.5.8. 默认 Web 模块行为的更改

在 JBoss EAP 7.0 中,mod_cluster 中默认禁用了 Web 应用的根上下文。

自 JBoss EAP 7.1 起,情况已不再如此。如果您希望禁用根上下文,这可能会造成意外的后果。例如,可以将请求错误路由到不合要求的节点,或者不应公开的私有应用可以通过公共代理意外访问。Undertow 位置现在会自动注册到 mod_cluster 负载平衡器,除非被明确排除。

使用以下管理 CLI 命令,将 ROOT 从 modcluster 子系统配置中排除:

/subsystem=modcluster/mod-cluster-config=configuration:write-attribute(name=excluded-contexts,value=ROOT)
Copy to Clipboard Toggle word wrap

使用以下管理 CLI 命令,禁用默认的欢迎 Web 应用:

/subsystem=undertow/server=default-server/host=default-host/location=\/:remove
/subsystem=undertow/configuration=handler/file=welcome-content:remove
reload
Copy to Clipboard Toggle word wrap

有关如何配置默认欢迎 Web 应用程序的更多信息,请参阅 JBoss EAP 开发指南中的配置默认欢迎 Web 应用

4.5.9. Undertow 子系统默认配置的更改

在 JBoss EAP 7.2 之前,默认的 undertow 子系统配置包含两个响应标头过滤器,它们附加至 default-host 各个 HTTP 响应中。

  • Server,设置为 JBoss-EAP/7
  • X-Powered-By,设置为 Undertow/1

这些响应标头过滤器已从默认的 JBoss EAP 7.2 配置中删除,以防止意外泄漏有关正在使用的服务器的信息。

以下是 JBoss EAP 7.1 中默认 undertow 子系统配置的示例。

<subsystem xmlns="urn:jboss:domain:undertow:4.0">
    <buffer-cache name="default"/>
    <server name="default-server">
        <http-listener name="default" socket-binding="http" redirect-socket="https"/>
        <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
        <host name="default-host" alias="localhost">
            <location name="/" handler="welcome-content"/>
            <filter-ref name="server-header"/>
            <filter-ref name="x-powered-by-header"/>
            <http-invoker security-realm="ApplicationRealm"/>
        </host>
    </server>
    <servlet-container name="default">
        <jsp-config/>
        <websockets/>
    </servlet-container>
    <handlers>
        <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    </handlers>
    <filters>
        <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
        <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
    </filters>
</subsystem>
Copy to Clipboard Toggle word wrap

以下是 JBoss EAP 7.4 中新默认 undertow 子系统配置的示例:

<subsystem xmlns="urn:jboss:domain:undertow:10.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other">
    <buffer-cache name="default"/>
    <server name="default-server">
        <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
        <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
        <host name="default-host" alias="localhost">
            <location name="/" handler="welcome-content"/>
            <http-invoker security-realm="ApplicationRealm"/>
        </host>
    </server>
    <servlet-container name="default">
        <jsp-config/>
        <websockets/>
    </servlet-container>
    <handlers>
        <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    </handlers>
</subsystem>
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat