Skip to content

Instantly share code, notes, and snippets.

@infynyxx
Forked from michaelklishin/browsers.conf
Created July 12, 2010 16:11
Show Gist options
  • Save infynyxx/472651 to your computer and use it in GitHub Desktop.
Save infynyxx/472651 to your computer and use it in GitHub Desktop.
How to limit browser support to only recent versions of Chrome, Firefox, Internet Explorer and Safari in Nginx
#
# Supported browsers
#
modern_browser gecko 1.9;
# note that Safari related directives match
# Chrome, Mobile Safari, Palm Pre and other WebKit-based browsers here, too, thanks
# to all of them using almost identical User-Agent strings
modern_browser safari 3.0;
modern_browser safari 3.1;
modern_browser safari 3.2;
modern_browser safari 4.0;
modern_browser msie 7.0;
modern_browser msie 8.0;
modern_browser unlisted;
#
# Non-supported browsers
#
ancient_browser msie 4.0;
ancient_browser msie 5.0;
ancient_browser msie 5.5;
ancient_browser msie 6.0;
# Here is how one can disable support of a specific browser
ancient_browser opera 7;
ancient_browser opera 8;
ancient_browser opera 9;
ancient_browser opera 10;
ancient_browser konqueror 3;
ancient_browser konqueror 4;
ancient_browser Links Lynx Netscape4;
#
# Now, to the fun part. If we perform a rewrite on every
# request here, images won't be displayed, so we have to
# do some extra work besides just
#
# if ($ancient_browser){
# rewrite ^ /unsupported_browser.html;
# break;
# }
set $unsupported_browser_rewrite do_not_perform;
if ($ancient_browser){
set $unsupported_browser_rewrite perform;
}
if ($uri !~* /\.(jpeg|jpg|png|ico|gif|js|css)$/) {
set $unsupported_browser_rewrite do_not_perform;
}
if ($unsupported_browser_rewrite = perform){
rewrite ^ /unsupported_browser.html;
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment