Welcome! Log In Create A New Profile

Advanced

Re: Dynamic Redirects

Harmer, Sean
April 07, 2010 04:38PM
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@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@engineyard.com
>
>
>
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://nginx.org/mailman/listinfo/nginx
>



--
Sean Harmer
seanharmer@gmail.com
703.957.9272
_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Dynamic Redirects

Harmer, Sean April 07, 2010 03:12PM

Re: Dynamic Redirects

Ezra Zygmuntowicz April 07, 2010 03:36PM

Re: Dynamic Redirects

Harmer, Sean April 07, 2010 04:38PM

Re: Dynamic Redirects

runesoerensen July 26, 2011 10:38PM

Re: Dynamic Redirects

Reinis Rozitis April 07, 2010 05:30PM

Re: Dynamic Redirects

Anonymous User April 07, 2010 06:24PM

Re: Dynamic Redirects

agentzh July 27, 2011 12:18AM

Re: Dynamic Redirects

Manlio Perillo April 07, 2010 05:44PM

Re: Dynamic Redirects

agentzh July 26, 2011 11:50PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 321
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready