Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have 2 applications running under the same server. The server is using Nginx to serve the Unicorn upstream of both apps, one is intended for mobile user and the other one is intended for all other users agents.

I have done some research and I have found that I can redirect requests to another path or domain if regex match but it seems to me that will hit infinite loop(haven't tried though) if I use that under my architecture.

 map $http_user_agent $ua_redirect {
    default '';
    ~(iPhone|Android) m.mydomain.com;
    ~(MSIE|Mozilla) mydomain.com;
  }

It looks like since every redirect will act as a new request to nginx and get redirected again. Will this be the case or am I missing something?

Mobile Application

upstream myapp-mobile.rails {
  server localhost:10001 fail_timeout=0;
}

server {
  server_name m.mydomain.com;
  listen 80;

  root /my/app-mobile/directory/current/public;


  access_log /var/log/nginx/myapp-mobile.rails-access.log combined;
  error_log  /var/log/nginx/myapp0mobile.rails-error.log;

  rewrite_log on;

  # use the application's 500.html page
  error_page 500 502 503 504 /500.html;

  # allow clients to upload large files (if necessary)
  client_max_body_size 4G;

  location / {
    try_files /system/maintenance.html
              $uri $uri/index.html $uri.html
              @app;
  }

location ~ ^/(assets)/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location @app {
    proxy_pass        http://shop.pr-mobile.rails;
    proxy_redirect    off;

    proxy_set_header  Host                $http_host;
    proxy_set_header  X-Real-IP           $remote_addr;
    proxy_set_header  X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto   $scheme;

    client_max_body_size        100m;
    client_body_buffer_size     128k;

    proxy_buffer_size           4k;
    proxy_buffers               4 32k;
    proxy_busy_buffers_size     64k;
    proxy_temp_file_write_size  64k;
  }
}

Web Application

upstream myapp-web.rails {
  server localhost:10001 fail_timeout=0;
}

server {
  server_name www.mydomain.com;
  listen 80;

  root /my/app/directory/current/public;


  access_log /var/log/nginx/myapp-web.rails-access.log combined;
  error_log  /var/log/nginx/myapp-web.rails-error.log;

  rewrite_log on;

  # use the application's 500.html page
  error_page 500 502 503 504 /500.html;

  # allow clients to upload large files (if necessary)
  client_max_body_size 4G;

  location / {
    try_files /system/maintenance.html
              $uri $uri/index.html $uri.html
              @app;
  }

  location ~ ^/(assets)/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location @app {
    proxy_pass        http://myapp-web.rails;
    proxy_redirect    off;

    proxy_set_header  Host                $http_host;
    proxy_set_header  X-Real-IP           $remote_addr;
    proxy_set_header  X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto   $scheme;

    client_max_body_size        100m;
    client_body_buffer_size     128k;

    proxy_buffer_size           4k;
    proxy_buffers               4 32k;
    proxy_busy_buffers_size     64k;
    proxy_temp_file_write_size  64k;
  }
}
share|improve this question
    
I see no redirects in your config. Also, do you really want to redirect all Android based tablets to mobile version? –  Alexey Ten Apr 1 at 6:38
    
Aaahhh, didn't think about Android tablets.. actually no, all tablets should go to mobile version is there any other way to match Android mobile only? –  Luis D Urraca Apr 2 at 15:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.