1

I'd like to make PC and mobile devices load different index's files.

So, before the nginx main "location", I tried creating an "if" like this:

# START MOBILE
if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {
    location / {
        try_files /my/dir/here/index-mobile.html $uri $uri/ /index.php ;
    }    
}

Howerver, I get "nginx: [emerg] "location" directive is not allowed here". Any ideas about how to make PC's show up index.html and make device browsers show up index-mobile.html?

bazaglia
  • 153
  • 1
  • 7
  • 2
    Your `if` statement needs to be within the `location`, not the other way around. That said, [If Is Evil](http://wiki.nginx.org/IfIsEvil) and you really should consider some [responsive web design](http://en.wikipedia.org/wiki/Responsive_web_design). – ceejayoz Jun 08 '13 at 21:32
  • +1 for responsive design. – Michael Hampton Jun 08 '13 at 21:39

0 Answers0