I've faced the same problem this week and this is my solution for it (see below for setup and who nginx was compiled)
Add this line under nginx.conf (it adds support for Lua, see below why)
lua_package_path '/usr/local/lib/lua/?.lua';
site config (in my case default):
upstream memcached {
server 127.0.0.1:11211;
keepalive 32;
}
server {
listen 8080 default_server;
root /usr/share/nginx/html;
index index.fhtml index.fhtm;
# Make site accessible from http://localhost/
server_name localhost;
location = /memc {
internal;
memc_connect_timeout 100ms;
memc_send_timeout 100ms;
memc_read_timeout 100ms;
memc_ignore_client_abort on;
set $memc_key $arg_key;
set $memc_exptime 300;
memc_pass memcached;
}
location /memc-stats {
add_header Content-Type text/plain;
set $memc_cmd stats;
memc_pass memcached;
}
location / {
set_by_lua $key 'return ngx.md5(ngx.arg[1])' $request_uri;
srcache_fetch GET /memc key=$key;
srcache_methods GET;
srcache_store_statuses 200 301 302;
proxy_pass http://127.0.0.1:80$request_uri;
set_by_lua $key 'return ngx.md5(ngx.arg[1])' $request_uri;
srcache_request_cache_control off;
srcache_store PUT /memc key=$key;
}
}
My setup is like on Ubuntu 14.04, nginx running on port 8080 and Apache on 80 (just to test this) with nginx 1.7.5 compiled with the following arguments under "full_configure_flags"
full_configure_flags := \
$(common_configure_flags) \
--with-http_addition_module \
--with-http_dav_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_secure_link_module \
--with-http_spdy_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-mail \
--with-mail_ssl_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--add-module=/opt/nginx/modules/ngx_devel_kit-0.2.19 \
--add-module=/opt/nginx/modules/set-misc-nginx-module-0.26 \
--add-module=/opt/nginx/modules/memc-nginx-module-0.15 \
--add-module=/opt/nginx/modules/srcache-nginx-module-0.28 \
--add-module=$(MODULESDIR)/headers-more-nginx-module \
--add-module=$(MODULESDIR)/nginx-auth-pam \
--add-module=$(MODULESDIR)/nginx-cache-purge \
--add-module=$(MODULESDIR)/nginx-dav-ext-module \
--add-module=$(MODULESDIR)/nginx-echo \
--add-module=$(MODULESDIR)/nginx-http-push \
--add-module=$(MODULESDIR)/nginx-lua \
--add-module=$(MODULESDIR)/nginx-upload-progress \
--add-module=$(MODULESDIR)/nginx-upstream-fair \
--add-module=$(MODULESDIR)/ngx_http_substitutions_filter_module
I've compiled Lua and other modules, as you can see. The need for Lua was because I wanted to have a consistent way to hash the values for the memcached keys without having to worry about what will happen if someone will send some unexpected values as well as be able to hash it in the same way from the backend.
Hope this helps you (and others).
EDIT:
You can get the modules that I've added from here: