Weird IE8 error. Nginx to the rescue!

04 Nov 2014

As a server side developer, I don’t run into IE-specific errors very often. Last month, I ran into a very specific error, which is spectacular by itself. IE8 does not like downloads with cache control headers. The client has plenty of IE8 users and preferred we serve over HTTP for IE8 so that the site worked for sure.

Nginx has a very handy module called ngx_http_browser_module to help! All that I needed to do was less than 10 lines of Nginx config.

location / {
    # every browser is to be considered modern
    modern_browser unlisted;
    # these particular browsers are ancient
    ancient_browser "MSIE 6.0" "MSIE 7.0" "MSIE 8.0";
    # redirect to HTTP if ancient
    if ($ancient_browser) {
        return 301 http://$server_name$request_uri;
    }
    # handle requests that are not redirected
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
}
It's Magic GIF

Yet another day I’m surprised by Nginx :)

All Posts ⇉

Comments

blog comments powered by Disqus