- Oh boy!, someone says, we need to build a python script that uses curl and download the images, that will take a while ... and bandwidth.
- OK we can cache, said a tech guy.
- Project is then delayed? freaked out the PM
- We need to negotiate ASAP, said the BA while running to his desk to write an email.
How many solutions a problem might have? Commonly more than one. What we need here has a name and actually a Pattern Name. We need a proxy, and apache has a proxy module, and that can be integrated with the rewrite module and so we can happily serve any image from our own domain even though the resource is located in an external server.
So in the apache conf file for the particular Virtual Host we include a rewrite rule:
<VirtualHost *>We hit http://images.mydomain.com/img.png. Bad luck, it does not work and from the log file we see:
#In production systems comment the below two lines
RewriteRule (.*) http://externaldomain.com/%1 [P,L]
File does not exist: proxy:http://externaldomain.com/img.png
Let us take a look at Server libraries
httpd -lVoila, mod-proxy support is not enabled. So after we recompile apache with support for mod-proxy:
./configure --prefix=/usr/local/apache --enable-so --enable-rewrite=shared --enable-ssl=shared --enable-proxy --enable-proxy-connect --enable-proxy-http
We do get what we expected (mod_proxy.c) and our image http://images.mydomain.com/img.png is showing up even though it does not exist in our domain but in the external server.