Ezra - Thank you.  That is very helpful.  <br><br>It brings up another question:  Once the match has been made in redis, is there a way to modify or append data to the User-Agent or HTTP HEADER?<br><br>Thanks again,<br>Sean<br>
<br><br><br><div class="gmail_quote">On Wed, Apr 7, 2010 at 3:30 PM, Ezra Zygmuntowicz <span dir="ltr">&lt;<a href="mailto:ezmobius@gmail.com">ezmobius@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5"><br>
On Apr 7, 2010, at 12:09 PM, Harmer, Sean wrote:<br>
<br>
&gt; NGINX Team,<br>
&gt;<br>
&gt; Is there a way to capture the User-Agent from an HTTP Header, then query a database for that User-Agent, then based on the result of the database query, transparently route the request to an appropriate server?<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Sean<br>
<br>
<br>
<br>
</div></div>Sean-<br>
<br>
<br>
        Here is one way to do what you want, you will need to use redis as the database to lookup your backend with. You will need to compile nginx with two additional modules:<br>
<br>
<a href="http://wiki.nginx.org/NginxHttpRedis" target="_blank">http://wiki.nginx.org/NginxHttpRedis</a><br>
<a href="http://www.grid.net.ru/nginx/eval.en.html" target="_blank">http://www.grid.net.ru/nginx/eval.en.html</a><br>
<br>
        Once you have both of those module compiled into your nginx you can use a config file like this:<br>
<br>
worker_processes  1;<br>
user root root;<br>
events {<br>
   worker_connections  1024;<br>
}<br>
<br>
http {<br>
   include       mime.types;<br>
   default_type  application/octet-stream;<br>
<br>
   sendfile        on;<br>
<br>
   log_format main &#39;$remote_addr - $remote_user [$time_local] &#39;<br>
                   &#39;&quot;$request&quot; $status $body_bytes_sent &quot;$http_referer&quot; &#39;<br>
                   &#39;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#39;;<br>
<br>
   keepalive_timeout  65;<br>
<br>
   server {<br>
       listen       80;<br>
       server_name  _;<br>
<br>
<br>
       access_log /var/log/nginx/redis.access.log main;<br>
<br>
       error_log /var/log/nginx/redis.error.log notice;<br>
<br>
       location / {<br>
               eval_escalate on;<br>
               eval $answer {<br>
                       set $redis_key  &quot;$http_user_agent&quot;;<br>
                       set $redis_db   &quot;0&quot;;<br>
                       redis_pass      <a href="http://127.0.0.1:6379" target="_blank">127.0.0.1:6379</a>;<br>
               }<br>
               proxy_pass $answer;<br>
<br>
       }<br>
   }<br>
}<br>
<br>
<br>
<br>
Then in redis you will need to store key value pairs mapping the $http_user_agent to the server:port combo that should serve that user agent type:<br>
<br>
redis.set &quot;some-user-agent&quot;, &quot;<a href="http://192.168.0.1:80" target="_blank">http://192.168.0.1:80</a>&quot;<br>
<br>
<br>
Then when a request comes into the nginx server and has a  $http_user_agent value of &quot;some-user-agent&quot;, redis will return <a href="http://192.168.0.1:80" target="_blank">http://192.168.0.1:80</a> and then nginx will proxy_pass to the particular server.<br>

<br>
<br>
Hope this helps point you in the right direction.<br>
<br>
<br>
Cheers-<br>
<br>
Ezra Zygmuntowicz<br>
<a href="mailto:ez@engineyard.com">ez@engineyard.com</a><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx" target="_blank">http://nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Sean Harmer<br><a href="mailto:seanharmer@gmail.com">seanharmer@gmail.com</a><br>703.957.9272<br>