Thanks for making this post @kp117! I have it on my list to dig into further next week and see if there is a simple fix. This is the type of thing that you are certainly welcome to share with our professional support team by emailing support@rstudio.com.
It is also a great resource to have publicly for other users to reference, so we appreciate you posting here!
One note off the top of my head. I think this line:
proxy_set_header X-RSC-Request scheme://$host:$server_port$request_uri;
Is missing a $ on scheme. Switching scheme to $scheme might solve your issue!
However, it looks like you may have another proxy in front of nginx terminating TLS. As a result, $scheme will be http and could still cause issues. As a result, you may want to replace $scheme with https (just hard-code it). So the line would look like this:
proxy_set_header X-RSC-Request https://$host:$server_port$request_uri;
In any case, can you say a bit more about your architecture? Is there another proxy in front of nginx, like a load balancer, etc.? If so, can you describe it / how it is configured?