简体   繁体   English

aws 弹性 beantalk 上的 HTTP 到 HTTPS 不适用于 Spring Boot

[英]HTTP to HTTPS on aws elastic beanstalk not working for Spring Boot

I'm trying to get http -> https working with elastic beanstalk, and their documentation doesn't seem to be working.我试图让 http -> https 与弹性 beantalk 一起工作,但他们的文档似乎不起作用。 I've set up the load balancer to terminate http and https successfully.我已经设置了负载平衡器以成功终止 http 和 https。

http://example.com
https://example.com

both work.两者都工作。

This documentation explains how to configure https to http redirects. 本文档解释了如何将 https 配置为 http 重定向。 I'm using java-se with Spring Boot, so I've read the readme and placed .ebextensions in my src/main/resources folder.我在 Spring Boot 中使用 java-se,所以我已经阅读了自述文件并将.ebextensions放在我的src/main/resources文件夹中。

So my finished spring boot jar has myapp.jar/BOOT-INF/classes/.ebextensions/nginx/conf.d/elasticbeanstalk/00_application.conf with:所以我完成的 spring boot jar 有myapp.jar/BOOT-INF/classes/.ebextensions/nginx/conf.d/elasticbeanstalk/00_application.conf与:

location / {
     set $redirect 0;
     if ($http_x_forwarded_proto != "https") {
       set $redirect 1;
     }
     if ($http_user_agent ~* "ELB-HealthChecker") {
       set $redirect 0;
     }
     if ($redirect = 1) {
       return 301 https://$host$request_uri;
     }

     proxy_pass          http://127.0.0.1:5000;
     proxy_http_version  1.1;

     proxy_set_header    Connection          $connection_upgrade;
     proxy_set_header    Upgrade             $http_upgrade;
     proxy_set_header    Host                $host;
     proxy_set_header    X-Real-IP           $remote_addr;
     proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
}

inside it.在里面。 But nothing redirects to https.但没有任何重定向到 https。

Alright, figured it out!好吧,想通了! Put .ebextensions in the root folder of your project, not src/main/resources ..ebextensions放在项目的根文件夹中,而不是src/main/resources Then add the bootJar command to stick that folder at the top level of the finished jar, where it needs to be for AWS to pick it up:然后添加bootJar命令以将该文件夹粘贴在完成的 jar 的顶层,AWS 需要在该位置提取它:

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ["-Xjsr305=strict"]
        jvmTarget = "1.8"
    }

    bootJar {
        from('.ebextensions') {
            into('.ebextensions' )
        }
    }
}

Thank you to the answer to this question for getting me the rest of the way there:感谢您对这个问题的回答,让我完成了剩下的工作:

How do you build a folder into the .jar root of a spring boot gradle project?如何在 spring boot gradle 项目的 .jar 根目录中构建文件夹?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS Elastic Beanstalk(单实例):如何为 Spring 启动应用程序启用 HTTPS? - AWS Elastic Beanstalk (single instance) : how to enable HTTPS for a Spring Boot application? Spring Boot Application无法在AWS Elastic Beanstalk中进行一次身份验证 - Spring Boot Application not authenticating once in AWS Elastic Beanstalk AWS Elastic Beanstalk上的Spring Boot / Tomcat仅显示404页面 - Spring Boot / Tomcat on AWS Elastic Beanstalk only showing 404 page 如何将Spring Boot应用程序大战部署到AWS Elastic Beanstalk? - How to deploy Spring Boot application war to AWS Elastic Beanstalk? 在AWS Elastic Beanstalk上部署Spring Boot应用程序 - 获得502错误 - Deploying Spring Boot app on AWS Elastic Beanstalk — getting 502 error AWS Elastic Beanstalk-Tomcat Java Spring Boot应用程序出现问题 - AWS Elastic Beanstalk - Problem with tomcat java spring boot application 使用自动 SSL 证书在 AWS Elastic Beanstalk 上部署 Spring Boot 应用程序 - Deploy Spring Boot application on AWS Elastic Beanstalk with automatic SSL certificates 在AWS Elastic Beanstalk上部署Spring - Deploying Spring on AWS Elastic Beanstalk 使用Elastic BeansTalk CLI部署Spring Boot应用程序 - Deploy Spring Boot application with Elastic BeansTalk CLI 在Elastic Beanstalk上使用Opencv运行Spring Boot - Running Spring boot with Opencv on Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM