Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created September 28, 2012 05:25
Show Gist options
  • Save jugyo/3798080 to your computer and use it in GitHub Desktop.
Save jugyo/3798080 to your computer and use it in GitHub Desktop.
switch rails page cache by user agent
http {
...
server {
listen 8080;
server_name localhost;
#
# Set User Agent type
#
set $ua_type "pc";
if ($http_user_agent ~* '(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)') {
set $ua_type "mobile";
}
location / {
root /var/www/app/public;
# Rewrite for page cache
#
# e.g.)
# pc: public/pc/xxx.html
# mobile: public/mobile/xxx.html
#
if (-f $realpath_root/$ua_type$uri) {
rewrite (.*) /$ua_type$1 break;
}
if (-f $realpath_root/$ua_type$uri/index.html) {
rewrite (.*) /$ua_type$1/index.html break;
}
if (-f $realpath_root/$ua_type$uri.html) {
rewrite (.*) /$ua_type$1.html break;
}
proxy_pass http://127.0.0.1:3000;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment