一、域名配置
我是在阿里云万网购买的域名,购买了域名后,进入控制台,域名部分;点击“解析”;
“添加记录”,A类,普通IPV4的地址;主机记录随便定义,习惯“www”;记录值:服务器对应的公网IP。保存->配置成功
访问URL:主机记录+域名+端口+url
二、springboot+tomcat https配置
1)、https配置
- 首先在阿里云申请SSL证书,有免费版本
- 购买之后,绑定之前申请的域名
- 审核完成后,下载证书,tomcat版
- springboot配置:将pfx文件放入resources目录下
- 配置xml文件:key-store-password:pfx-password.txt内容
2)、http转发https
package com.twenty.percent.server.config;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Description: 配置https
* @Author: zx
* @Time: 2020-03-16 15:03
**/
@Configuration
public class ConnectorConfig {
//http
@Value("10443")
private int serverPortHttp;
//https
@Value("${server.port}")
private int serverPortHttps;
@Bean
public ServletWebServerFactory servletWebServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
@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);
}
};
factory.addAdditionalTomcatConnectors(redirectConnector());
return factory;
}
private Connector redirectConnector() {
Connector connector = new Connector(Http11NioProtocol.class.getName());
connector.setScheme("http");
connector.setPort(serverPortHttp);
connector.setSecure(false);
connector.setRedirectPort(serverPortHttps);
return connector;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。