簡體   English   中英

aws 彈性 beantalk 上的 HTTP 到 HTTPS 不適用於 Spring Boot

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

我試圖讓 http -> https 與彈性 beantalk 一起工作,但他們的文檔似乎不起作用。 我已經設置了負載平衡器以成功終止 http 和 https。

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

兩者都工作。

本文檔解釋了如何將 https 配置為 http 重定向。 我在 Spring Boot 中使用 java-se,所以我已經閱讀了自述文件並將.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。

好吧,想通了! .ebextensions放在項目的根文件夾中,而不是src/main/resources 然后添加bootJar命令以將該文件夾粘貼在完成的 jar 的頂層,AWS 需要在該位置提取它:

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

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

感謝您對這個問題的回答,讓我完成了剩下的工作:

如何在 spring boot gradle 項目的 .jar 根目錄中構建文件夾?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM