Reverse Proxy to firebase authentication for simple NextJS app

I am running a simple NextJS application and I need a reverse proxy to handle firebase auth (as described here) similar to below:

location /__/auth {

I tried to add nginx.config but getting unhealthy allocations errors at deploy.

Is there an easier, faster way to add simple reverse proxies directly on fly.toml on the same machine without having to add nginx to the Dockerfile or without having to run a standalone nginx app?

Usually, health indications might indicate the app failed to communicate with our platform for example the port was wrong or the app didn’t start/listen to that before the timeout or it wasn’t listening to loopback IP. Logs could help with this. Maybe Nginx didn’t start?

I can see that your proxy needs to live on a path to your website, Nginx is a good way to handle that, I’ve also seen some people talk about Caddy, you can find examples for both on this forum. Our toml file doesn’t support reverse proxies inside it. I suggest baking it on your Dockerfile so your instances know how to handle it.

1 Like

The simple solution to the original problem is to use NextJS rewrites rather than a reverse proxy. Add the following to your config object in file next.config.js.

  async rewrites() {
    return [
        source: "/__/auth/:path*",
        destination: `*`,

Thanks for sharing this with the community @titocosta

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.