Connect Nginx Load Balancer with Memcache server


I m using Nginx as Load balancer with ngx_http_memcached_module and I installed a Memcached Server that I would like to connect it with Nginx to make it obtain responses from a Memcached server.

Load balancer.conf (Nginx)

upstream backend  {
#  least_conn;
  server weight=1 max_fails=3  fail_timeout=30s;
  server weight=2 max_fails=3  fail_timeout=30s;
        proxy_buffer_size 1k;
        proxy_buffers 24 4k;

        proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=backcache:8m max_size=50m;
        proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args";
        proxy_cache_valid 200 302 10m;
        proxy_cache_valid 404 1m;

server {
 listen 80;

 location / {
   proxy_cache backcache;
   proxy_cache_bypass $http_cache_control;
   add_header X-Proxy-Cache $upstream_cache_status;
   proxy_pass  http://backend;

location /wp-admin {

Memcached Conf:


Nginx Example Configuration from the official website

But I don’t understand what each ligne is doing and can’t apply it to my server.

server {
    location / {
        set            $memcached_key "$uri?$args";
        memcached_pass host:11211;
        error_page     404 502 504 = @fallback;

    location @fallback {
        proxy_pass     http://backend;

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.