Do not expose HTTP 302 redirect by HTTP reverse proxy – handle it internally

Daniel asked:

I’m creating a Facebook client for a very limited device – its web browser (ANT Galio) does not handle properly HTTP302 for source of images.

My UC looks like this – in web application markup profile images are placed in the manner:

<img src="http://reverseproxyfqdn/graph.facebook.com/profileId/picture/" />

When proxy asks for graph.facebook.com/profileId/picture/ it gets HTTP 302 redirect to different address, for example fbcdn-profile-a.akamaihd.net/someUrl. This response is reverse proxied to web browser with Location header changed to reverseproxyfqdn/fbcdn-profile-a.akamaihd.net/someUrl. All the web browsers I’ve tested handle it properly, but not ANT Galio. I need to return image got from fbcdn-profile-a.akamaihd.net/someUrl directly as a response to reverseproxyfqdn/graph.facebook.com/profileId/picture/ – so do not expose the whole HTTP 302 redirect story to the web browser.

Does anyone know how to do it in Nginx or Apache 2.2? I would like to avoid creating a special PHP/Perl/Java app for this and achieve it by HTTP server configuration.

My answer:


Don’t send the graph.facebook.com/.../picture/... URLs to the browser in the first place. Instead, resolve them yourself on the server side while you’re creating the HTML pages and insert the CDN URLs in their place.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.