Spring Boot重定向到https

时间:2016-07-05 00:48:26

标签: tomcat ssl browser spring-boot centos

我使用centos 7,spring boot(使用tomcat嵌入式)

在我的application.properties

www.xxxx.com

我可以通过

访问我的网站
xxxx.com

但是

server.port: 8443

不起作用

我也尝试了

在我的application.properties

@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;
}

在Application类

s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8443 (https) 8080 (http)

在日志中我看到了

xml.css("Duration")

www.xxxxx.com正在运作

xxxx.com会自动转换为

xxxx.com:8443

我不明白为什么添加端口。

1 个答案:

答案 0 :(得分:0)

可能禁用此指令可以避免端口重定向:

connector.setRedirectPort(8443);

但是您必须考虑到其他设置也很有意义。

相关问题