I'm trying to get http -> https working with elastic beanstalk, and their documentation doesn't seem to be working. I've set up the load balancer to terminate http and https successfully.
http://example.com
https://example.com
both work.
This documentation explains how to configure https to http redirects. I'm using java-se with Spring Boot, so I've read the readme and placed .ebextensions
in my src/main/resources
folder.
So my finished spring boot jar has myapp.jar/BOOT-INF/classes/.ebextensions/nginx/conf.d/elasticbeanstalk/00_application.conf
with:
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.
Alright, figured it out! Put .ebextensions
in the root folder of your project, not 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:
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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.