Created
September 28, 2012 05:25
-
-
Save jugyo/3798080 to your computer and use it in GitHub Desktop.
switch rails page cache by user agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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