【问题标题】:HTTP to HTTPS on aws elastic beanstalk not working for Spring Bootaws弹性beantalk上的HTTP到HTTPS不适用于Spring Boot
【发布时间】:2019-06-07 22:09:47
【问题描述】:

我正在尝试让 http -> https 与弹性豆茎一起使用,但他们的文档似乎不起作用。我已设置负载均衡器以成功终止 http 和 https。

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

两者都有效。

This documentation 解释了如何配置 https 到 http 的重定向。我在 Spring Boot 中使用 java-se,所以我阅读了 the readme 并将 .ebextensions 放在我的 src/main/resources 文件夹中。

所以我完成的 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;
}

在里面。但是没有任何东西重定向到https。

【问题讨论】:

  • 你能编辑.httpaccess吗?
  • @Ismael 您的意思是像登录负载平衡器的服务器并手动更改它?理论上我可以,但它不会自动工作,如果我有另一个环境,我必须手动重做。

标签: java amazon-web-services spring-boot amazon-elastic-beanstalk


【解决方案1】:

好吧,想通了!将.ebextensions 放在项目的根文件夹中,而不是src/main/resources。然后添加 bootJar 命令将该文件夹粘贴到已完成 jar 的顶层,AWS 需要将其拾取:

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

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

感谢您对这个问题的回答让我顺利完成了剩下的工作:

How do you build a folder into the .jar root of a spring boot gradle project?

【讨论】:

    猜你喜欢
    • 2013-07-20
    • 2018-10-18
    • 2016-04-15
    • 1970-01-01
    • 2021-04-07
    • 2016-11-29
    • 2015-05-22
    • 2014-01-26
    • 2018-10-26
    相关资源
    最近更新 更多