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'm trying to configure handle request direct from nginx using redis cache, cache already added to redis the problem is to configure nginx get the cache from redis

URL is like http://example.com/action.js?param1=10&param2=text

Redis key is depend on param1

in the following example it use the full path as the key for redis

so i want to capture the param1 to get key which is like "cahced_page_"+param1

server {
  listen 80;
  server_name your.website.com;
  root /home/appuser/app/current/public;
  error_log /dev/null crit; #real man don't log
  location / {
      set $redis_db "1";
      set $redis_key $uri;
      default_type   text/html;
      redis_pass redis;
      error_page 404 405 502 504 = @fallback;
  }

  location @fallback {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      if (!-f $request_filename) {
          proxy_pass http://yourunicornupstream;
          break;
      }
  }

}
share|improve this question
1  
Did you check wiki.nginx.org/HttpCoreModule#Variables ? -> Especially the part about $arg_PARAMETER ? –  etagenklo Nov 27 '13 at 21:06
    
Yee, thanks for help on this –  mohamed-stark Nov 28 '13 at 14:45

1 Answer 1

from http://wiki.nginx.org/HttpEchoModule#Variables

location = /code.js {
  set $redis_db "1";
  set $redis_key "hashed_key_$arg_param1";
  default_type   text/javascript;
  redis_pass redis;
  error_page 404 405 502 504 = @fallback;
}
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.