【问题标题】:nginx memcachednginx 内存缓存
【发布时间】:2012-10-25 07:49:52
【问题描述】:

我尝试将 nginx 与 memcached 搭配使用:

server {

    ...

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

    location @fallback {
        include uwsgi_params;
        uwsgi_pass unix:///var/tmp/site.sock;
    }

}

但是所有请求都转到 uwsgi 而不使用 memcache:

nginx -V

nginx -V nginx 版本:nginx/1.1.19 启用 TLS SNI 支持配置 参数:--prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var /lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp- path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var /run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with- http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-dav-ext-module

输出中没有 ngx_http_memcached_module。

我使用 Ubuntu 12.04 和安装了 apt-get install nginx 的 nginx。

这是否意味着我必须安装它才能使用 memcached 或其他东西?

【问题讨论】:

  • 嗨,你是怎么安装那个模块的?

标签: nginx memcached


【解决方案1】:

来自http://nginx.org/en/docs/http/ngx_http_memcached_module.html#memcached_pass

The ngx_http_memcached_module module allows to obtain responses from a memcached 
server. The key is set in the $memcached_key variable. A response should be put 
in memcached in advance via means that are external to nginx. 

换句话说,nginx 只能检索已经存储在 memcache 中的东西

means that are external to nginx 应该是你的 uwsgi 应用程序

【讨论】:

  • 谢谢,它澄清了.. 但是是否可以通过 nginx 填充 memcached 而无需在后端执行,nginx 收到结果,为什么它不能将它保存在 memcached 中?
  • 不知道为什么会这样,因为我猜到目前为止没有人费心去实现它
  • 有一个第 3 方模块支持 set,见 wiki.nginx.org/HttpMemcModule(注意第 3 方模块意味着你必须自己编译 nginx)
  • @cobaco 我在 Ubuntu 12.04 上从 apt-get 安装 nginx 时包含了 ngx_http_memcached_module,但在 14.04 上没有。编辑:它没有在任何安装的configure arguments 中列出。很奇怪。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 1970-01-01
  • 2017-03-07
  • 1970-01-01
  • 2020-09-17
  • 2021-01-30
相关资源
最近更新 更多