java - 如何通过 443 以外的端口使用带有 HTTPS 的嵌入式 Jetty?

标签 java ssl https jetty embedded-jetty

我一直在 Ubuntu 14.04(使用自签名证书)上使用嵌入式 Jetty(我们称其为 serverA)在默认端口 443 上通过 HTTPS 提供 Web 应用程序。多年来它一直运行良好,但我想在同一台机器上运行另一个嵌入式 Jetty Web 服务器 (serverB)。我希望 serverB 使用默认端口 443 运行 SSL,因此我需要更改 serverA 以监听其他端口上的请求。

我一直在尝试使用 444 和 8080 的 serverA。服务器正常启动,告诉我它正在正确的端口上监听请求。但请求只是挂起,服务器日志什么也没告诉我。如果我启动服务器监听端口 443,那么一切正常。

只要我将 Web 服务器配置为使用 SSL,我认为使用哪个端口并不重要。我还需要做些什么吗?

这是我的启动代码:

    // Java 7 bug (feature?) - this disables SNI everywhere...
    // required or else outgoing HTTPS requests will fail
    System.setProperty("jsse.enableSNIExtension", "false");

    PropertyConfigurator.configure("./log4j.properties");
    Server server = new Server();

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar("war");
    server.setHandler(webapp);

    HttpConfiguration https = new HttpConfiguration();
    https.addCustomizer(new SecureRequestCustomizer());

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath("keystore.jks");
    sslContextFactory.setKeyStorePassword("password");
    sslContextFactory.setKeyManagerPassword("password");

    ServerConnector sslConnector = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, "http/1.1"),
            new HttpConnectionFactory(https));
    sslConnector.setPort(port);

    server.setConnectors(new Connector[] { sslConnector });

    try {
        LOG.info("Starting server on port " + port);
        server.start();
        server.join();

    } catch (Exception e) {
        LOG.fatal("The web server has crashed", e);
    }

注意:这是在 StackOverflow 而不是 SuperUser 或其他东西上的原因,据我所知,用于 HTTPS 的端口并不重要。那么我假设这是 Jetty 问题。

编辑:
抱歉,忘了提 Jetty 版本。现在是 9.2.0

最佳答案

试试这个,因为你没有告诉 jetty 什么被认为是安全的,它只是使用默认值。

HttpConfiguration https = new HttpConfiguration();
https.setSecurePort(port); /* missing this */
https.addCustomizer(new SecureRequestCustomizer());

这可能看起来很奇怪,但实际上是需要的,因为即使连接以不安全的方式到达,您也可以被认为是安全的。例如从代理或 jetty 前的 ssl 终止负载均衡器(多种方式非常惊人)

关于java - 如何通过 443 以外的端口使用带有 HTTPS 的嵌入式 Jetty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26163162/

相关文章:

ruby-on-rails - 使用 Rails 3.1 的 Heroku 中特定于 SSL 的主机名

c - 如何添加证书文件以在没有文件系统的操作系统上设置 libcurl HTTPS 连接?

http - nginx.conf中 '='登录的含义

java - 我可以使用哪个 Java 工作流框架将其与 gui 绑定(bind)

java - 在 Java 中将图像的元数据转换为 JSON

Tomcat 在 APR Connector (SSL) init 上挂起

ssl - 使用 TLS 从 Go 客户端进行 gRPC 调用 - GCP 云功能

java - 选择文本需要 XPath 建议

java - 在android中连接2个字符串?

scala - WSClient Play Framework SSL 设置