The upstream (origin) server is running nginx and hosting our static React app.
We need to implement a 301 HTTP redirect in our application to redirect my.company.com → app.company.com. We are attempting to implement this by adding an ingress object to our environment that looks something like this:
Note: FRONTEND_APP is an environment variable that you have defined in the Qovery environment variable. {$FRONTEND_APP} is the Caddy syntax to declare an environment variable.
Advantages
This is a much better and simpler way than modifying the NGINX ingress controller on your Kubernetes controller.
There is no risk that the configuration breaks in case of a Kubernetes upgrade
The container can be scaled the way you want - it’s stateless
You can version (GitOps) the caddy configuration into Git
user request → AWS load balancer → ingress nginx → caddy service → nginx container serving app
With requests for both the primary domain, app.company.com, and the host we want to redirect, my.company.com, going through Caddy. (although, I suppose we could route only my.company.com through Caddy)
Since this is a one-off use case for us, we’ve decided to just add the redirect directly into the nginx app container, which seems simplest, and should be good enough for now.
Is there a timeframe on your roadmap for supporting redirects through ingresses in the UI?
Yes it is safe to do, the service name of the app is not going to change once created. One caveat, though, is that you will not be able to clone this environment, as your new ingress will not follow/or the service name is not going to change.
Another option you have, is to declare a 2nd domain app.company.com on your service, and in your code have a handler that returns a 301 permanent redirect if the host header is not matching app.company.com