title: Nginx dynamic location depending on device used
body: <p>What I'm trying to do is to specify the location if the user accessed our website by mobile or by web. This is my configuration on the sites-enabled file:
  <strong>PLEASE TAKE NOTE ON THE COMMENT THE LINE THAT IS STARTED BY A SHARP</strong></p>
  
  <pre><code>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 $is_mobile {
      1 0;
      0 1;
  }
  
  server {
  
      listen 80;
      server_name example.com;
      charset utf-8;
      if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
          set $year $1;
          set $month $2;
          set $day $3;
      }
      access_log /usr/logs/nginx/lion/lion.$year-$month-$day.log;
  
      if ($is_mobile) {
          location / {
              root /usr/src/app1
      }
  
      if ($is_desktop) {
          location / {
              root /usr/src/app2;
          }
      }
  
      error_page  405     =200 $uri;
  }
  </code></pre>
  
  <p><strong>TAKE NOTE THAT THE DOMAIN WILL NOT CHANGE AND SUB-DOMAIN will not be used</strong></p>
  
  <p>It's like using a different front-end code set to be used to render on the domain depending on the device used. Is it possible?</p>