问题描述
我正在尝试启用Jetty的https端口。 Jetty在Karaf服务器中运行。
虽然在网上找到了不同的建议配置:
-
https://karaf.apache.org/manual/latest/的版本
<!-- Use this connector for many frequently idle connections and for threadless continuations. --> <Call name="addConnector"> <Arg> <New class="org.eclipse.jetty.server.nio.SelectChannelConnector"> <Set name="host"> <Property name="jetty.host" /> </Set> <Set name="port"> <Property name="jetty.port" default="8181" /> </Set> <Set name="maxIdleTime">300000</Set> <Set name="Acceptors">2</Set> <Set name="statsOn">false</Set> <Set name="confidentialPort">8443</Set> <Set name="lowResourcesConnections">20000</Set> <Set name="lowResourcesMaxIdleTime">5000</Set> </New> </Arg> </Call>
-
https://www.eclipse.org/jetty/documentation/9.1.5.v20140505/configuring-connectors.html的另一个版本
<New id="tlsHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration"> <Arg> <New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration"> <Set name="secureScheme">https</Set> <Set name="securePort"> <Property name="jetty.tls.port" default="8443"/> </Set> <Set name="outputBufferSize">32768</Set> <Set name="requestHeaderSize">8192</Set> <Set name="responseHeaderSize">8192</Set> <!-- Uncomment to enable handling of X-Forwarded- style headers <Call name="addCustomizer"> <Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg> </Call> --> </New> </Arg> <Call name="addCustomizer"> <Arg> <New class="org.eclipse.jetty.server.SecureRequestCustomizer"/> </Arg> </Call>
我没有两种工作方法。您是否有关于如何调试此问题以及实际上正确的方法的任何提示?
解决方法
对于稳定版本(非EOL)的Jetty,例如Jetty 9.4.x ...
HttpConfiguration.securePort
(ServerConnector
上存在的配置)是逻辑端口,用于标识对您的客户端公开可见的安全端口。
以这个用例为例。
- 公共Internet上的浏览器请求
https://acme.com/foo
- 浏览器为
acme.com
查找DNS并获取210.1.1.1
- 浏览器在端口
210.1.1.1
上连接到443
- 负载均衡器/代理正在监听
210.1.1.1:443
并接受请求。 - Load Balancer添加了
Forwarding
标头并连接到内部IP10.2.2.2:8443
- 在
10.2.2.2:8443
上侦听的Jetty服务器接受连接并处理请求。
这时,Jetty服务器上的配置在端口ServerConnector
上有一个8443
,端口HttpConfiguration.securePort
的值是443
,因为这是公用端口浏览器看到的。