Help!!!! FastAPI uvicorn app behind Cloudflare proxy
Hi
I have a fast api uvicorn app running behind an nginx on a GCP VM with statis IP.
I am using CloudFlare as my DNS. I have 2 records.
1. The first record DOES NOT use Cloudflare proxy. I am correctly able to make Rest calls to the FastAPI server using both http and https
2. The second record has Cloudflare proxy enabled. When trying to call the rest api now, I get "Bad Gateway Error".
Does anyone know what special configuration do I need to do for Uvicorn, Nginx, FastAPI, or Cloudflare to prevent this error. I would obviously like to use Cloudflare proxy for additional security and performance benefits it provides.
2 Replies
Looking forward to any tip.
Hi, not sure if you figured it out but I am using a similar set up, except for caddy instead of nginx, fastapi/uvicorn behind it - I had some issues using the cloudflare proxy at first but ended up fixing it. I would probably need to think about what I did but I recall there was a setting required to make it work. Now my site basically runs behind cloudflare without any issue.
I have a second site using cloudflare on gcp vm but it's a django site, sitting behind a caddy server as well. Both had the same issue.