In my case adding nginx headers and fastapi config for the proxy headers did not work.
I had to hardcode the replacement of http to https in the 307 redirect responses (through a middleware) as follows:
if response.status_code == 307
and request.headers.get("x-forwarded-proto") == "https":
response.headers["Location"] = response.headers["Location"].replace('http://', 'https://')