When nginx encounters a https
protocol it thinks it is still using http
as the protocol and is not being forwarded with the rest of the headers, try adding:
proxy_set_header X-Forwarded-Proto $scheme;
in your location blocks to fix it.