Score:0

Trouble getting NGINX to serve static content for specific directory from CDN via proxy

cn flag
Ren

I would like to serve static files from my remote CDN URL:

https://my.cdn.com/project/files/2023/01/some_image.png

https://my.cdn.com/project/files/2021/04/some_file.txt

These need to be reached via proxy from my website URLs (without redirecting) at:

https://my.website.com/files/2023/01/some_image.png

https://my.website.com/files/2021/04/some_file.txt

Having trouble getting this to work via NGINX's try_files.

Here's what my current NGINX config for this looks like:

location /files/ {
    try_files $uri @cdn;
}

location @cdn {
  set $cdn_url   'my.cdn.com';
  set $url_full         'project/$1';

  proxy_set_header       Host $cdn_url;
  proxy_set_header       Authorization '';
  proxy_pass             https://$cdn_url$url_full;
}

I've read through and tried some of the solutions here, but I can't seem to get it working: https://stackoverflow.com/questions/2045869/nginx-proxy-to-files-on-local-disk-or-s3

What am I doing wrong?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.