Skip to content

Reverse Proxy to App Runner application

0

I'm trying to reverse proxy from a subdomain to multiple web applications running both on Tomcat (from an ec2 instance) and App Runner. It works perfectly for the Tomcat applications, but I get a 404 error when trying to access my App Runner applications.

I prefer to do this with Caddy, but have also tried nginx. Both fail. Here's an example of my Caddy config:

app.example.com {
    reverse_proxy /AppunnerApp* https://xxxxxxxxx.us-east-2.awsapprunner.com {
        header_up Host {upstream_hostport}
    }   
    
    reverse_proxy /TomcatApp1* X.X.X.X:8080
    reverse_proxy /TomcatApp2* X.X.X.X:8080
    reverse_proxy /TomcatApp3* X.X.X.X:8081
}

I've verified I can proxy other https websites with the configuration above. This seems to be something with App Runner. Has anyone tried this? Any ideas what could be causing the failure?

Thanks

asked 2 years ago376 views

1 Answer
0
Accepted Answer

The issue you're experiencing with reverse proxying to your App Runner application is likely related to how App Runner handles incoming requests. App Runner uses the Host header information to route requests, which is crucial for proper routing.

In your Caddy configuration, you're setting the Host header to the upstream host and port. However, for App Runner, this might not be the correct approach. Instead, you should try setting the Host header to the App Runner service URL.

Here's a modified version of your Caddy configuration that might work:

app.miottawa.org {
    reverse_proxy /AppunnerApp* https://xxxxxxxxx.us-east-2.awsapprunner.com {
        header_up Host xxxxxxxxx.us-east-2.awsapprunner.com
    }   
    
    reverse_proxy /TomcatApp1* X.X.X.X:8080
    reverse_proxy /TomcatApp2* X.X.X.X:8080
    reverse_proxy /TomcatApp3* X.X.X.X:8081
}

In this modified configuration, we're explicitly setting the Host header to the App Runner service URL instead of using the {upstream_hostport} variable.

If you're still encountering issues, here are a few additional things to check:

  1. Ensure that your App Runner service is configured to accept traffic from your reverse proxy's IP address.

  2. Verify that the App Runner service URL you're using is correct and that the service is running.

  3. Check if your App Runner service has any path-based routing configured. If it does, you may need to adjust your reverse proxy configuration accordingly.

  4. If you're using HTTPS, make sure that your reverse proxy is correctly handling SSL/TLS termination and that it's forwarding requests to App Runner over HTTPS.

  5. Consider enabling logging on your reverse proxy to get more detailed information about the requests and responses, which could help in troubleshooting.

If these suggestions don't resolve the issue, you may want to contact AWS support for further assistance, as there could be specific configurations or limitations with App Runner that are causing the 404 errors.
Sources
HTTP/HTTPS request routing error - AWS App Runner
Release: App Runner adds support for redirecting HTTP requests to HTTPS endpoints on February 22, 2023 - AWS App Runner

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Many thanks! The {upstream_hostport} includes the correct host, but adds the port. For some reason App Runner doesn't like the port included. I updated my config to use {http.reverse_proxy.upstream.host} instead which resolves to the config you have above and it works great!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.