0

I have a set of rules in Nginx of this type:

location ~ ^/race/[a-z0-9\-_]*/session/[a-z0-9\-]*/topic/[a-z0-9\-_]*$ {
   try_files $uri $uri/ /race/period/session/team/topic/index.html;
}

location /images/assets/ {
   try_files /backup/data$uri /default_images/small_asset.png =404;
}

These rules work when the files exist on the server but now the data is in a remote location (AWS - S3+cloudfront) I need to use proxy_pass, but wondering how to deal with cases when I have multiple choices like:

try_files $uri $uri/ /race/period/session/team/topic/index.html;

And

try_files /backup/data$uri /default_images/small_asset.png =404;

How to handle the first path in a remove endpoint for example:

location /images/assets/ {
   proxy_pass http://abc.cloudfront.net/backup/data 
   # but if I get a 404 here,how to fall back to: 
   proxy_pass http://abc.cloudfront.net/default_images/small_assets.png
}

Any ideas? not necessary I need to use Nginx now that the content is hosted remotely, open to any alternatives.

nbari
  • 548
  • 1
  • 8
  • 25
  • 1
    To fallback on 404 you would need to use `error_page`. See [this document](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page). – Richard Smith May 12 '22 at 07:30
  • any idea how to also deal with the regex when using proxy_pass? – nbari May 13 '22 at 09:47

0 Answers0