How to Fix Redirects from ECS API to Point to Public DNS?

0
8
Asked By TechyCat123 On

Hey everyone! I'm dealing with an issue where my ECS Fargate API, which is in a private subnet and exposed to the internet via APIGateway, VPC link, and NLB, is returning a 302 redirect that points to the internal NLB address. This means that when the redirect occurs, it tries to access my NLB in the private subnet and fails. I'm hoping to modify the redirect headers so that they point to the public DNS instead. Any ideas on what I might be missing? This has been really frustrating!

2 Answers

Answered By CodeNinja42 On

You can’t redirect public users to a private API endpoint since it won’t work. If the private endpoint needs to be accessible from the public, consider redirecting to a publicly available reverse proxy that can handle your API requests.

Answered By DebugDiva99 On

The reason your app is generating those redirects using the internal NLB hostname is because that’s what it identifies. To fix this, you should utilize the original host from the incoming request. Check out the X-Forwarded-Host header instead, and configure your application to trust proxy headers, which should allow the redirects to use the public URL.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.