第 17 章 配置 Web 服务器(Undertow)
17.1. Undertow 子系统概述
在 JBoss EAP 7 中,undertow
子系统取代了 JBoss EAP 6 中的 Web
子系统。
undertow
子系统可用于配置 Web 服务器和 servlet 容器设置。它实施 Jakarta Servlet 4.0 规范和 websocket。它还支持 HTTP 升级,并在 servlet 部署中使用高性能非阻塞处理程序。undertow
子系统也能够充当支持 mod_cluster 的高性能反向代理。
在 undertow
子系统内,需要配置五个主要组件:
尽管 JBoss EAP 确实提供了更新每个组件的配置,但默认配置适用于大多数用例,并且提供合理的性能设置。
默认 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>
undertow
子系统也依赖于 io
子系统来提供 XNIO 工作线程和缓冲区池。The io
子系统单独配置,提供默认配置,这在大部分情形中都能提供最佳性能。
与 JBoss EAP 6 中的 Web
子系统相比,JBoss EAP 7 中的 undertow
子系统具有不同的 HTTP 方法默认行为。
将 Elytron 与 Undertow 子系统搭配使用
部署 Web 应用时,将识别该应用所需的安全域名称。这可以来自部署内部,或者部署没有安全域,则将假定 undertow
子系统中定义的 default-security-domain
。默认情况下,假定安全域映射到旧安全子系统中定义的 PicketBox
。不过,可以将 application-security-domain
资源添加到 undertow
子系统中,该子系统从应用所需的安全域名称映射到适当的 Elytron 配置。
示例:添加映射.
/subsystem=undertow/application-security-domain=ApplicationDomain:add(security-domain=ApplicationDomain)
如果结果为:
<subsystem xmlns="urn:jboss:domain:undertow:10.0" ... default-security-domain="other"> ... <application-security-domains> <application-security-domain name="ApplicationDomain" security-domain="ApplicationDomain"/> </application-security-domains> ... </subsystem>
- 如果此时部署部署,应重新加载应用服务器,使应用安全域映射生效。
- 在当前的 Web service-Elytron 集成中,为保护 Web 服务端点而指定的安全域名称,Elytron 安全域名必须相同。
这种简单形式适合在部署中使用 Servlet 规范中定义的标准 HTTP 机制,如 BASIC
、CLIENT_CERT
、DIGEST
、FORM
。此处将对 ApplicationDomain 安全域
进行身份验证。此表单也适用于应用不使用任何身份验证机制,而是使用编程身份验证,或者试图获取与部署关联的 SecurityDomain
并直接使用。
示例:映射的高级表单:
/subsystem=undertow/application-security-domain=MyAppSecurity:add(http-authentication-factory=application-http-authentication)
如果结果为:
<subsystem xmlns="urn:jboss:domain:undertow:10.0" ... default-security-domain="other"> ... <application-security-domains> <application-security-domain name="MyAppSecurity" http-authentication-factory="application-http-authentication"/> </application-security-domains> ... </subsystem>
在这种配置形式中,引用 http-authentication-factory
,而不是引用安全域。这是用于获取身份验证机制实例且与安全域关联的工厂。
在使用自定义 HTTP 身份验证机制时,或者必须针对主体转换器、凭据工厂和机制域等机制定义其他配置时,您应该引用 http-authentication-factory
属性。在使用 Servlet
规范中描述的四种机制之外,最好使用 http-authentication-factory
属性引用 http-authentication-factory 属性。
使用高级形式的映射时,可以使用另一个配置选项 override-deployment-config
。引用的 http-authentication-factory
可以返回一整套身份验证机制。默认情况下,这些将被过滤为仅与应用请求的机制匹配。如果此选项设为 true
,则工厂提供的机制将覆盖应用请求的机制。
application-security-domain
资源还有一个额外的选项 enable-jacc
。如果设置为 true,则
对于与此映射匹配的任何部署,将启用 JACC。
Runtime Information
如果使用 application-security-domain
映射,可以重复检查部署是否按预期与其匹配。如果资源使用 include-runtime=true
读取,与映射关联的部署也将显示为:
/subsystem=undertow/application-security-domain=MyAppSecurity:read-resource(include-runtime=true) { "outcome" => "success", "result" => { "enable-jacc" => false, "http-authentication-factory" => undefined, "override-deployment-config" => false, "referencing-deployments" => ["simple-webapp.war"], "security-domain" => "ApplicationDomain", "setting" => undefined } }
在此输出中,reference -deployments
属性显示已使用该映射部署了 simple-webapp.war
部署。