简体   繁体   English

Tomcat Http和Https在同一个端口上

[英]Tomcat Http and Https on the same port

I have a web-service endpoint and a http connector on port X. At some point this endpoint needs to switch to https, but on the same port! 我在端口X上有一个Web服务端点和一个http连接器。在某些时候,此端点需要切换到https,但在同一端口上! (I know this is not the normal way of doing things, but this is what my clients expect from an old server they are using...) (我知道这不是正常的做事方式,但这是我的客户对他们正在使用的旧服务器的期望...)

Is there a way to do it in tomcat? 有没有办法在tomcat中做到这一点?

This is not possible with Tomcat.The HTTPS connector will accept SSL connection only. Tomcat无法做到这一点.HTTP连接器仅接受SSL连接。

We have such a proxy developed in house. 我们在内部开发了这样的代理。 It's not that hard to do. 这并不难。 You just need to check the first incoming packet. 您只需要检查第一个传入的数据包。 Looking for the pattern of SSL handshake. 寻找SSL握手的模式。 We only look for CLIENT_HELLO. 我们只寻找CLIENT_HELLO。 Once you figure out the protocol, you can forward the request accordingly. 一旦找出协议,就可以相应地转发请求。

This is really ugly. 这真的很难看。 You shouldn't do it if all possible. 如果可能的话,你不应该这样做。 We have to do it because the legacy clients do this and it's impossible to upgrade them all. 我们必须这样做,因为传统客户端会这样做,并且无法全部升级它们。

There is such a thing as HTTPS upgrade, whereby a plaintext HTTP connection is upgraded to HTTP by mutual agreement after it has been formed. 存在HTTPS升级这样的事情,即明文HTTP连接在形成之后通过相互协商升级到HTTP。 Is that what you mean? 你是这个意思吗? If so, Tomcat doesn't seem to support it out of the box, and neither does Java out of the box either. 如果是这样,Tomcat似乎不支持开箱即用,Java也不开箱即用。 You can probably write yourself a Tomcat Connector that will do it; 您可以自己编写一个可以执行此操作的Tomcat连接器; on the client end you have a more interesting problem ;-) 在客户端你有一个更有趣的问题;-)

But I would ask why? 但我会问为什么? Ports aren't so expensive that you can't use two. 端口不是那么昂贵,你不能使用两个。

您不需要在同一端口上运行HTTP和HTTPS,配置Tomcat以将请求重定向到server.xml文件中的HTTPS。

well I wonder why they are NOT usually on the same port! 好吧,我想知道为什么他们通常不在同一个港口! wouldn't that be easier? 会不会更容易?

the reason is probably that related Java APIS (javax.net.ssl) don't allow that; 原因可能是相关的Java APIS(javax.net.ssl)不允许这样做; you must have different server sockets. 你必须有不同的服务器套接字。 are there any alternative SSL impls for Java? 是否有任何替代SSL impls for Java? I'm not aware of any. 我不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM