一舌胶、域名配置
我是在阿里云萬網(wǎng)購買的域名,購買了域名后答倡,進(jìn)入控制臺(tái)轰传,域名部分;點(diǎn)擊“解析”瘪撇;
“添加記錄”获茬,A類,普通IPV4的地址倔既;主機(jī)記錄隨便定義恕曲,習(xí)慣“www”;記錄值:服務(wù)器對(duì)應(yīng)的公網(wǎng)IP渤涌。保存->配置成功
訪問URL:主機(jī)記錄+域名+端口+url
二佩谣、springboot+tomcat https配置
1)、https配置
- 首先在阿里云申請(qǐng)SSL證書实蓬,有免費(fèi)版本
- 購買之后茸俭,綁定之前申請(qǐng)的域名
- 審核完成后,下載證書安皱,tomcat版
- springboot配置:將pfx文件放入resources目錄下
-
配置xml文件:key-store-password:pfx-password.txt內(nèi)容
2)调鬓、http轉(zhuǎn)發(fā)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;
}
}