[英]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.