未在 url 中使用端口

Not using port in the url

我使用 spring 引导(tomcat 嵌入式)和 ssl。

实际上,我需要在 url 中输入端口 (8443) 才能访问 Web 应用程序。

如何可以只使用域名?

有点像 https://www.bob.com

而不是

https://www.bob.com:8443/

编辑

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat
            = new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(createHttpConnector());
    return tomcat;
}

private Connector createHttpConnector() {
    Connector connector
            = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    connector.setSecure(false);
    connector.setPort(8080);
    connector.setRedirectPort(8443);
    return connector;
}

现在不需要输入端口

但如果输入 bob.com,浏览器将转换为

bob.com:8443

你的意思是这样的吗?

String webPort = System.getenv("PORT");

    if(webPort == null || webPort.isEmpty()) {
        webPort = "8080";
    }

浏览器用于 HTTP 的默认端口是 80,HTTPS 是 443。如果您 运行 您的应用程序在 443 上(因为您使用的是 HTTPS),则不必使用端口号,浏览器将自动重新路由您的 URL。要更改 spring-boot 应用程序中的端口号,请在 bootstrap.yml.

中指定 server.port 属性
server:
  port: 443