nginx没有缓存来自反向代理的响应

时间:2016-08-23 22:32:02

标签: nginx memcached

http://nginx.org/en/docs/http/ngx_http_memcached_module.html

基本配置在这里:

worker_processes  2;

events {
    worker_connections  1024;
}

error_log  /var/log/nginx/nginx_error.log  warn;
error_log  /var/log/nginx/nginx_error.log  info;

http {
    upstream backend {
        server localhost:3000;
    }

  server {
      listen 80;

      location / {
          set            $memcached_key $uri;
          memcached_pass 127.0.0.1:11211;
          error_page     404 = @fallback;
      }

      location @fallback {
          proxy_pass     http://backend;

      }
  }
}

它在命中端口80时反向代理请求,但日志总是说:

2016/08/23 15:25:19 [info] 68964#0: *4 key: "/users/12" was not found by memcached while reading response header from upstream, client: 127.0.0.1, server: , request: "GET /users/12 HTTP/1.1", upstream: "memcached://127.0.0.1:11211", host: "localhost"

1 个答案:

答案 0 :(得分:0)

Nginx Memcached模块不会写入Memcached服务器。您应该使用$ memcached_key

在后端(例如PHP)中执行此操作