FAQ

Page Discussion Edit History

NginxHttpMemcachedModule

Contents

Edit section: Synopsis Synopsis

You can use this module to perform simple caching. There are plans to extend this module in the near future.

Example configuration

server {
  location / {
    set $memcached_key $uri;
    memcached_pass     name:11211;
    default_type       text/html;
    error_page         404 = /fallback;
  }
 
  location = /fallback {
    proxy_pass backend;
  }
}

Or, if using Nginx 0.7.x:

server {
  location / {
    set $memcached_key $uri;
    memcached_pass     name:11211;
    default_type       text/html;
    error_page         404 @fallback;
  }
 
  location @fallback {
    proxy_pass backend;
  }
}

Edit section: Directives Directives

Edit section: memcached_pass memcached_pass

syntax: memcached_pass [ name:port ]

default: none

context: http, server, location

The backend should set the data in memcached. The memcached key is "/uri?args".

Since 0.5.9 the memcached key is now in $memcached_key.

Edit section: memcached_connect_timeout memcached_connect_timeout

syntax: memcached_connect_timeout [ time ]

default: 60000

context: http, server, location

The timeout for connecting to memcached, in milliseconds.

Edit section: memcached_read_timeout memcached_read_timeout

syntax: memcached_read_timeout [ time ]

default: 60000

context: http, server, location

The timeout for reading from memcached, in milliseconds.

Edit section: memcached_send_timeout memcached_send_timeout

syntax: memcached_send_timeout [ time ]

default: 60000

context: http, server, location

The timeout for sending to memcached, in milliseconds.

Edit section: memcached_buffer_size memcached_buffer_size

syntax: memcached_buffer_size [ size ]

default: see getpagesize(2)

context: http, server, location

The recv/send buffer size, in bytes.

Edit section: memcached_next_upstream memcached_next_upstream

syntax: memcached_next_upstream [ error | timeout | invalid_response | not_found | off ]

default: error timeout

context: http, server, location

Which failure conditions should cause the request to be forwarded to another upstream server? Applies only when the value in memcached_pass is an upstream with two or more servers.

Edit section: Variables Variables

Edit section: $memcached_key $memcached_key

The value of the memcached key.

Edit section: References References

Edit section: Speeding up your nginx server with memcached Speeding up your nginx server with memcached

[1] Speeding up your nginx server with memcached

Edit section: See Also See Also

  • The 3rd-party memc module that supports almost the whole memcached TCP protocol.