后端服务器如何映射https

2022年 10月 17日 发表评论
免费、便宜/高性价比 服务器汇总(已更新):点击这里了解

在后端服务器中设置映射https,具体方法如下:

public class Http2HttpsConfig {

/**

* 配置服务器容器

*/

@Bean

public EmbeddedServletContainerFactory servletContainer(){

TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(){

@Override

protected void postProcessContext(Context context) {

SecurityConstraint securityConstraint = new SecurityConstraint();

securityConstraint.setUserConstraint("CONFIDENTIAL");

SecurityCollection securityCollection = new SecurityCollection();

securityCollection.addPattern("/*");

securityConstraint.addCollection(securityCollection);

context.addConstraint(securityConstraint);

}

};

tomcat.addAdditionalTomcatConnectors(httpConnector());

return tomcat;

}

/**

* 设置http到https的url映射

*/

@Bean

public Connector httpConnector(){

Connector connector = new Connector(">connector.setScheme("http");

connector.setPort(8080);

connector.setSecure(false);

connector.setRedirectPort(8088);

return connector;

}

}

小咸鱼

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: