Skip to content

Instantly share code, notes, and snippets.

@libkazz
Forked from jugyo/nginx.conf
Created September 28, 2012 06:09
Show Gist options
  • Select an option

  • Save libkazz/3798193 to your computer and use it in GitHub Desktop.

Select an option

Save libkazz/3798193 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
#
try_files $ua_type$uri $ua_type$uri.html $ua_type$uri/index.html @localhost;
}
location @localhost {
proxy_pass http://127.0.0.1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment