Mobile Redirection with Nginx

Our company website automatically redirects visitors on mobile devices to its mobile counterpart. I was initially handling the checking/redirecting in the Ruby on Rails application using an implementation that is like the one shown in Railscast Episode 199. However, I have since made the mobile website a separate application and put it on its own subdomain, so I wanted to move the redirection logic out of the main Rails app.