Tuesday, April 13, 2010

reverse proxy overriding content-type

I had some links to images hosted on http servers which reported application/octet-stream instead of an 'image' mime type.

My application relied on that and I had to find a quick way to fix this by putting a reverse proxy in front of that particular server and override the content type.

I tried with no luck to do it with apache2 but it appears that there is no way to set the content-type response header after it's generated by the mod_proxy module.

So I tried out nginx, but it turns out that even nginx cannot force headers, but only add new headers

However the nginx docs point to a 3rd party module . Unfortunately the ubuntu nginx distribution didn't have this module compiled in, so I had to recompile nginx with this module built in. It turned out to be a simple operation.

I managed to reuse the same ubuntu nginx configuration files, by simply installing the custom nginx in /opt/nginx and symlinking ubuntu /etc/nginx to /opt/nginx/conf and changing the /etc/init.d/nginx script to point to /opt/nginx/sbin/nginx instead of /usr/sbin/nginx

then I simply added this line in my 'server' section:

   more_set_headers 'Content-Type: image/jpeg';