0

我制作了示例 Springboot 应用程序,其中包含以下代码application.propertied

server.ssl.enabled=true
server.ssl.key-store=src/main/resources/SpringSecurity.p12
server.ssl.key-store-password=password
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=SpringSecurity

以下两种方法也在 SpringBoot 的主类中

      @Bean
      public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat =
            new TomcatServletWebServerFactory() {
              @Override
              protected void postProcessContext(Context context) {
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
              }
            };
        tomcat.addAdditionalTomcatConnectors(redirectConnector());
        return tomcat;
      }

      private Connector redirectConnector() {
        Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(8082);
        return connector;
      }

如果我像 https://localhost:8082/hello 这样在 tomcat 中运行这个应用程序,它会像自签名一样工作。如果我点击 http://localhost:8082/hello,tomcat 会按预期显示错误的请求。事实上,它也从 8080 重定向到 8082。

现在我将其导出为.war文件。

现在我通过上传上面的 war 文件在 AWS Elastic Beanstalk 中创建一个应用程序。

如果我运行生成的 url : http://SpringSecurity-env.eba-wwpkejwp.us-east-2.elasticbeanstalk.com/hello,它可以正常工作,因为它是 http。

我需要在 https 上工作。有人可以建议我在 AWS/war 文件上配置/添加/删除什么吗?

4

1 回答 1

0

要使您的应用程序通过 HTTPs 工作,最简单的方法包括:

  • 负载平衡的 EB 环境与 Application Load Balancer 一起使用,
  • 注册您自己的域,例如在 Route53 中。您的域是必需的,因为您只能为您控制的域注册有效的公共 SSL 证书(非自签名)。
  • 拥有域后,您可以在 ACM 中为其申请免费 SSL证书。
  • 然后使用HTTPS 侦听器在 ALB 上部署 SSL 证书。

相关AWS 文档

于 2020-07-19T22:53:49.280 回答