http { ... server { ... location / { try_files $uri $uri/ @memcached; } location @memcached { default_type text/html; set $memcached_key DATAPREFIX$scheme://$host$request_uri; memcached_pass MEMCACHEDHOST:MEMCACHEDPORT; error_page 404 = @rewrites; } location @rewrites { rewrite ^(.*)$ /index.php?q=$1 last; } ... } } ...