After hours of testing and Googling I have a fix for the solution. There were other similar ones out there but none that were exactly what I was trying to do. Here is what I ended up doing to get that to work.
First I created a variable map that conditionally sets the value based on the $http_referer value that is within NGINX
map $http_referer $resources_location {
default "url.com";
"~*/page2" "url2.com";
"~*/page3" "url2.com";
}
This takes the variable $http_referer and sets the variable $resources_location based on the value of the $http_referer.
the default is the main url, and then I have regex expressions to determine of the page has /page2, /page3 in it.
The one catch I assume is https://url.com/page2 would trigger it, so would https://url.com/sub/page2. I do not have the need to worry about that, but one might so I would test also.
Then I use the new variable that is set in the proxy
location /sites/default/files/ {
proxy_set_header Host $resources_location;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_pass https://${resources_location};
}
Im a newbie to NGINX, so if there is something that can be done better, let me know!!