Dynamic Redirects
Harmer, Sean
seanharmer at gmail.com
Thu Apr 8 00:33:12 MSD 2010
Ezra - Thank you. That is very helpful.
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?
Thanks again,
Sean
On Wed, Apr 7, 2010 at 3:30 PM, Ezra Zygmuntowicz <ezmobius at gmail.com>wrote:
>
> On Apr 7, 2010, at 12:09 PM, Harmer, Sean wrote:
>
> > NGINX Team,
> >
> > 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?
> >
> > Thanks,
> > Sean
>
>
>
> Sean-
>
>
> 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:
>
> http://wiki.nginx.org/NginxHttpRedis
> http://www.grid.net.ru/nginx/eval.en.html
>
> Once you have both of those module compiled into your nginx you can
> use a config file like this:
>
> worker_processes 1;
> user root root;
> events {
> worker_connections 1024;
> }
>
> http {
> include mime.types;
> default_type application/octet-stream;
>
> sendfile on;
>
> log_format main '$remote_addr - $remote_user [$time_local] '
> '"$request" $status $body_bytes_sent "$http_referer" '
> '"$http_user_agent" "$http_x_forwarded_for"';
>
> keepalive_timeout 65;
>
> server {
> listen 80;
> server_name _;
>
>
> access_log /var/log/nginx/redis.access.log main;
>
> error_log /var/log/nginx/redis.error.log notice;
>
> location / {
> eval_escalate on;
> eval $answer {
> set $redis_key "$http_user_agent";
> set $redis_db "0";
> redis_pass 127.0.0.1:6379;
> }
> proxy_pass $answer;
>
> }
> }
> }
>
>
>
> 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:
>
> redis.set "some-user-agent", "http://192.168.0.1:80"
>
>
> Then when a request comes into the nginx server and has a $http_user_agent
> value of "some-user-agent", redis will return http://192.168.0.1:80 and
> then nginx will proxy_pass to the particular server.
>
>
> Hope this helps point you in the right direction.
>
>
> Cheers-
>
> Ezra Zygmuntowicz
> ez at engineyard.com
>
>
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>
--
Sean Harmer
seanharmer at gmail.com
703.957.9272
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20100407/4007a275/attachment-0001.html>
More information about the nginx
mailing list