当前位置:   article > 正文

https 请求 调用 http接口

https 请求 调用 http接口

1.首先去腾讯云或者阿里云申请免费ssl证书 不要自己生产 ,不然无法在服务器上使用
2. 获取证书之后 会生成一个 压缩包 打开 tomcat 的 文件 会有一个 text 文件 和 jks 文件
3.因为springboot使用的是内置tomcat,所以我这边选择tomcat文件,在resources目录下导入xxx.jks
密码在同文件夹的keystorePass.txt中

server:
  port: 10001
  ssl:
    key-store: classpath:xxxxx.com.jks
    key-password: u1u7497mw9835c
    key-store-type: JKS
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4.编写配置类

@Configuration
public class TomcatConfig {
    @Bean
    TomcatServletWebServerFactory tomcatEmbeddedServletContainerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(){
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint constraint = new SecurityConstraint();
                constraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                constraint.addCollection(collection);
                context.addConstraint(constraint);
            }
        };
        factory.addAdditionalTomcatConnectors(createTomcatConnector());
        return factory;
    }

    private Connector createTomcatConnector() {
        Connector connector = new
                Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(443);
        return connector;
    }
}

nginx 代理转发  
  location /api/ {
    proxy_pass  https://192.168.1.1:8088/deom/;
    
     }



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/1015924
推荐阅读
相关标签
  

闽ICP备14008679号