[英]AWS Elastic Beanstalk (single instance) : how to enable HTTPS for a Spring Boot application?
[英]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' )
}
}
}
感谢您对这个问题的回答,让我完成了剩下的工作:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.