Hey everyone so I configured my ELB to use an SSL certificate and it works great, however, I still have a problem where if a user comes to my website on port 80 under HTTP the website does not redirect them to an HTTPS secure connection. Heres a screenshot of my ELB configuration as seen in the Elastic Beanstalk configuration tab. Any help is appreciated thank you.
4 Answers
It wasn't the elb at all I simply had to add this code:
if (process.env.NODE_ENV === "production" || process.env.NODE_ENV === "awsDevelopmentServer") {
app.use(function(req, res, next) {
// Insecure request?
if (req.get("x-forwarded-proto") == "http") {
// Redirect to https://
return res.redirect("https://" + req.get("host") + req.url);
}```
1 Comment
While it seems like you got it working by redirecting in your application, it is possible to do this redirect entirely in your ALB. Documentation: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html
This feature was released in July 2018. https://aws.amazon.com/about-aws/whats-new/2018/07/elastic-load-balancing-announces-support-for-redirects-and-fixed-responses-for-application-load-balancer/
Elastic Beanstalk may not have launched their own support to configure this. You may be able to configure it via ebextensions, but for now it may be best to just do it in your application.
Comments
In fact, you can no longer do it from the Elastic Beanstalk interface.
Also don't do it from the app, bad solution for load.
You must now go to the EC2 load balancer and change the listener to port 80, as described here: