I am developing an application, where I use most of the photos provided by a third party service. While building my first prototype, I got the images directly from the service, i.e.
<img src="http://thirdpartyservice.com/img/12345.jpg">
It production though, it makes no sense grabbing the images from the service every time they get requested. It is just to too slow, because it serves millions of users at the same time.
I'd like to build a thin layer on top of nginx, which fetches, and caches images for 24 hours based on demand. So instead of calling the service every time, I'd rather call
<img src="http://myapp.com/img?url=thirdpartyservice.com/img/12345.jpg">
If this is the first time an image is requested, it will be fetched from the remote service and cached on my servers for 24 hours.
Is this possible to do with nginx?