SpringBoot配置https(SSL证书)

1. 将生成的密钥证书拷贝到项目中的resource中

2. yml配置文件,进行SSL配置

custom:
  http:
    port: 8002 # 自定义http启动端口
 
server: # https端口
  port: 8443
  ssl:
    key-store: classpath:cert.pfx # pfk存放路径
    key-store-type: PKCS12  # tomcat服务器类型默认
    key-store-password:XXXX #  密码

3、添加配置类,让http重定向

4. 配置 nginx ,使用域名进行访问

将前端的http协议,重定向到https协议,https协议默认是443端口,所以还需要在443端口进行配置,这里需要配置ssl证书路径

server
{
    listen 80;
    server_name suqiqaq.cn;
    index index.php index.html index.htm default.php default.htm default.html;
    # ssl证书路径
    ssl_certificate     /home/cert/8002091_suqiqaq.cn.pem;
    ssl_certificate_key /home/cert/8002091_suqiqaq.cn.key;
    root /home/hospital/app-api/dist;
   
    # $request_uri #包含请求参数的原始URI,不包含主机名
    # 如:”/foo/bar/arg”
    # $server_name #服务器名称
    # 将请求转成https,https协议默认是443端口,所以还需要在443端口进行配置
    return 301 https://$server_name$request_uri;
}
经验分享 程序员 微信小程序 职场和发展