Summary:
I'm trying to proxy images over Apache to Google Cloud.
In case of image does not exist, I want to forward a request to a different route which will return the image and save it on Google Cloud for the next time.
Legends:
Local media domain used for proxy: media.homestead
The site where the request should be forwarded(no redirect) if the image does not exist: mainsite.homestead
Google cloud bucket: storage.googleapis.com/mymedia.appspot.com
Case 1:
http://media.homestead/dimension/150x100/sport.jpg
The image exists on google cloud, so the user will get an image response.
Case 2:
http://media.homestead/dimension/600x400/sport.jpg
The image does not exist, and the user should get a response from mainsite.homestead/dimension/150x100/sport.jpg
Why?
Because there is ErrorDocument 403 to cover that case. We get header status 403 from Google Cloud if the image does not exist.
Configuration which I'm using for Apache:
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
<VirtualHost *:80>
ServerName media.homestead
ServerAdmin webmaster@localhost
ServerAlias media.homestead
Header always append X-Frame-Options SAMEORIGIN
Header always append X-XSS-Protection "1; mode=block"
Header always append X-Content-Type-Options nosniff
Header unset X-GUploader-UploadID
Header unset alt-svc
Header unset alternate-protocol
Header unset x-goog-hash
Header unset x-goog-generation
Header unset x-goog-metageneration
Header unset x-goog-stored-content-encoding
Header unset x-goog-stored-content-length
Header unset x-goog-storage-class
Header unset Set-Cookie
RequestHeader set X-SCHEME https
RequestHeader set X-Forwarded-Proto https
RequestHeader set Host "https://storage.googleapis.com/mymedia.appspot.com"
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
ProxyErrorOverride On
<Location />
ProxyPass http://storage.googleapis.com/mymedia.appspot.com/
ProxyPassReverse http://storage.googleapis.com/mymedia.appspot.com/
</Location>
<Location /media>
ProxyPass http://mainsite.homestead/dimension
ProxyPassReverse http://mainsite.homestead/dimension
</Location>
ErrorDocument 403 /media
ErrorDocument 404 /media
</VirtualHost>
Content of PHP script on mainsite.homestead:
<?php
echo $_SERVER['REQUEST_URI'];exit;
Problem:
Problem is that when I print the current URL on mainsite, I get "/dimension" instead of "/dimension/600x400/sport.jpg"