1

I'm using Nginx to serve a Drupal site and with Boost.

So far it's been working fine, but recently we added a mobile version and i configured boost/drupal to cache the mobile version in another directory, however i'm triying to configure Nginx to check for the adecuate directory if the device is mobile, but i'm getting 404 for some pages, and others never ever hit the cached files.
I've a location @cache with something like this:

set $mobile_rewrite desktop;
if ($http_user_agent ~ (iPhone|Android) ) {
    set $mobile_rewrite mobile;
}
try_files /cache/normal/$mobile_rewrite/$host${uri}_$args.html /cache/$host${uri}_$args.html @drupal;

When hitting the frontpage with a mobile user agent, i get served the mobile version, but every time it recreates it (so it goes to the @drupal location), and if i try to navigate further in the site (with mobile user agent) i get a 404 error

Any ideas?

I solved it using custom error and different locations.

4

1 回答 1

0

我终于解决了这个问题,为此,我改变了方法,而不是尝试使用变量更改 try_files 指令,我这样做了:

设置“地图”来检查用户代理并确定是否移动:

#Inside my http block
map $http_user_agent $is_desktop {
  default 0;
  ~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
  ~*spider|crawl|slurp|bot 1; # bots
  ~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
}
map $is_desktop $mobile_device {
  1 0;
  0 1;
}

然后在我的服务器块中,在默认 / 位置:

error_page 418 = @mobile; #defined a new error page pointing to a @location  
    if ($mobile_device) { #checking for above variable/map if true, goes to @location defined in error
           return 418;
    }

这个新位置与我之前的@cache 完全相同,但指向另一个目录。
希望它可以帮助别人!

于 2012-10-05T02:50:03.067 回答