dynamic default_type

Ilya Grigorik ilya at fortehost.com
Tue Feb 5 00:38:18 MSK 2008

I'm trying to integrate Nginx memcached module as a front-end server for serving
cached requests, but the problem is, the application type is defined dynamically
as part of the query string.. For example:

GET /test?format=xml 
GET /test?format=json

The requests get cached by Nginx and memcached, but on subsequent queries, they
are returned as default 'octetstream', which is not very useful.. So I've got as
far as creating a dynamic variable in my config:

 90         location /test {
 91            if ($args ~* format=json) { set $type "text/javascript"; }
 92            if ($args ~* format=xml)  { set $type "application/xml"; }
 94            default_type $type;
 95            ...
 95         }

The problem is, default_type does not seem to evaluate the parameter and returns
the literal string "$type". Any ideas on how to get it to return the actual
string it points to?

I also tried breaking up the queries by location regex:
 82         location ~* test.*format=xml {
 83             default_type application/xml;
 84             ...
 88         }

But the regex does not seem to pass or is invalid. 

Any tips would be appreciated..

More information about the nginx mailing list