Nginx中文文档
DocsHome
  • 贡献导引
  • 介绍
    • 安装 nginx
    • 从源码构建 nginx
    • 初学者指南
    • 管理指南
    • 控制 nginx
    • 连接处理方式
    • 设置哈希
    • 调试日志
    • 记录日志到 syslog
    • 配置文件度量单位
    • 命令行参数
    • Windows 下的 nginx
    • QUIC 和 HTTP/3 支持
    • nginx 如何处理请求
    • 服务器名称
    • 使用 nginx 作为 HTTP 负载均衡器
    • 配置 HTTPS 服务器
    • nginx 如何处理 TCP/UDP 会话
    • 关于 nginScript
  • 其他
    • Linux 软件包
  • How-To
    • 在 Win32 平台上使用 Visual C 构建 nginx
    • 设置 Amazon EC2 的 Nginx Plus 环境
    • 使用 DTrace pid 提供程序调试 nginx
    • 转换重写规则
    • WebSocket 代理
  • 开发
    • 贡献指南
    • 开发指南
  • 模块参考
  • 核心功能
    • HTTP
      • ngx_http_core_module
      • ngx_http_access_module
      • ngx_http_addition_module
      • ngx_http_api_module
      • ngx_http_auth_basic_module
      • ngx_http_auth_jwt_module
      • ngx_http_auth_request_module
      • ngx_http_autoindex_module
      • ngx_http_browser_module
      • ngx_http_charset_module
      • ngx_http_dav_module
      • ngx_http_empty_gif_module
      • ngx_http_f4f_module
      • ngx_http_fastcgi_module
      • ngx_http_flv_module
      • ngx_http_geo_module
      • ngx_http_geoip_module
      • ngx_http_grpc_module
      • ngx_http_gunzip_module
      • ngx_http_gzip_module
      • ngx_http_gzip_static_module
      • ngx_http_headers_module
      • ngx_http_hls_module
      • ngx_http_image_filter_module
      • ngx_http_index_module
      • ngx_http_js_module
      • ngx_http_keyval_module
      • ngx_http_limit_conn_module
      • ngx_http_limit_req_module
      • ngx_http_log_module
      • ngx_http_map_module
      • ngx_http_memcached_module
      • ngx_http_mirror_module
      • ngx_http_mp4_module
      • ngx_http_perl_module
      • ngx_http_proxy_module
      • ngx_http_random_index_module
      • ngx_http_realip_module
      • ngx_http_referer_module
      • ngx_http_rewrite_module
      • ngx_http_scgi_module
      • ngx_http_secure_link_module
      • ngx_http_session_log_module
      • ngx_http_slice_module
      • ngx_http_spdy_module(过时)
      • ngx_http_split_clients_module
      • ngx_http_ssi_module
      • ngx_http_ssl_module
      • ngx_http_status_module(过时)
      • ngx_http_stub_status_module
      • ngx_http_sub_module
      • ngx_http_upstream_module
      • ngx_http_upstream_conf_module
      • ngx_http_upstream_hc_module
      • ngx_http_userid_module
      • ngx_http_uwsgi_module
      • ngx_http_v2_module
      • ngx_http_xslt_module
    • Mail
      • ngx_mail_core_module
      • ngx_mail_auth_http_module
      • ngx_mail_proxy_module
      • ngx_mail_ssl_module
      • ngx_mail_imap_module
      • ngx_mail_pop3_module
      • ngx_mail_smtp_module
    • Stream
      • ngx_stream_core_module
      • ngx_stream_access_module
      • ngx_stream_geo_module
      • ngx_stream_geoip_module
      • ngx_stream_js_module
      • ngx_stream_keyval_module
      • ngx_stream_limit_conn_module
      • ngx_stream_log_module
      • ngx_stream_map_module
      • ngx_stream_proxy_module
      • ngx_stream_realip_module
      • ngx_stream_return_module
      • ngx_stream_split_clients_module
      • ngx_stream_ssl_module
      • ngx_stream_ssl_preread_module
      • ngx_stream_upstream_module
      • ngx_stream_upstream_hc_module
      • ngx_stream_zone_sync_module
    • 其他
      • ngx_google_perftools_module
由 GitBook 提供支持
在本页
  • 示例配置
  • 指令
  • memcached_bind
  • memcached_buffer_size
  • memcached_connect_timeout
  • memcached_force_ranges
  • memcached_gzip_flag
  • memcached_next_upstream
  • memcached_next_upstream_tries
  • memcached_pass
  • memcached_read_timeout
  • memcached_send_timeout
  • 内嵌变量
  • 原文档
  1. 核心功能
  2. HTTP

ngx_http_memcached_module

上一页ngx_http_map_module下一页ngx_http_mirror_module

最后更新于5年前

ngx_http_memcached_module 模块用于从 memcached 服务器上获取响应。key 设置在 $memcached_key 变量中。应通过 nginx 之外的方式提前将响应放入 memcached。

示例配置

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

    location @fallback {
        proxy_pass     http://backend;
    }
}

指令

memcached_bind

-

说明

语法

memcached_bind address [transparent ] | off;

默认

——

上下文

http、server、location

提示

该指令在 0.8.22 版本中出现

连接到一个指定了本地 IP 地址和可选端口(1.11.2)的 memcached 服务器。参数值可以包含变量(1.3.12)。特殊值 off (1.3.12)取消从上层配置级别继承的 memcached_bind 指令的作用,其允许系统自动分配本地 IP 地址和端口。

transparent 参数(1.11.0)允许出站从非本地 IP 地址到 memcached 服务器的连接(例如,来自客户端的真实 IP 地址):

memcached_bind $remote_addr transparent;

memcached_buffer_size

-

说明

语法

memcached_buffer_size size;

默认

memcached_buffer_size 4k|8k

上下文

http、server、location

设置用于读取从 memcached 服务器收到的响应的缓冲区的大小(size)。一旦收到响应,响应便会同步传送给客户端。

memcached_connect_timeout

-

说明

语法

memcached_connect_timeout time;

默认

memcached_connect_timeout 60s

上下文

http、server、location

定义与 memcached 服务器建立连接的超时时间。需要说明的是,超时通常不能超过 75 秒。

memcached_force_ranges

-

说明

语法

memcached_force_ranges on | off;

默认

memcached_force_ranges off;

上下文

http、server、location

提示

该指令在 1.7.7 版本中出现

无论响应中的 Accept-Ranges 字段如何,都对来自 memcached 服务器的缓存和未缓存的响应启用 byte-range 支持。

memcached_gzip_flag

-

说明

语法

memcached_gzip_flag flag;

默认

——

上下文

http、server、location

提示

该指令在 1.3.6 版本中出现

启用对 memcached 服务器响应中的 flag 存在测试,并在 flag 设置时将 Content-Encoding 响应头字段设置为 gzip。

memcached_next_upstream

-

说明

语法

memcached_next_upstream error | timeout | invalid_response | not_found | off ...;

默认

memcached_next_upstream error timeout;

上下文

http、server、location

指定在哪些情况下请求应传递给下一台服务器:

  • error

    在与服务器建立连接、传递请求或读取响应头时发生错误

  • timeout

    在与服务器建立连接、传递请求或读取响应头时发生超时

  • invalid_response

    服务器返回空或无效的响应

  • not_found

    在服务器上未找到响应

  • off

    禁用将请求传递给下一个服务器。

我们应该记住,只有在没有任何内容发送给客户端的情况下,才能将请求传递给下一个服务器。也就是说,如果在响应传输过程中发生错误或超时,修复这样的错误是不可能的。

memcached_next_upstream_tries

-

说明

语法

memcached_next_upstream_tries number;

默认

memcached_next_upstream_tries 0;

上下文

http、server、location

提示

该指令在 1.7.5 版本中出现

memcached_pass

-

说明

语法

memcached_pass address;

默认

——

上下文

http、location 中 if

设置 memcached 服务器地址。该地址可以指定为域名或 IP 地址以及端口:

memcached_pass localhost:11211;

或使用 UNIX 域套接字路径:

memcached_pass unix:/tmp/memcached.socket;

memcached_read_timeout

-

说明

语法

memcached_read_timeout time;

默认

memcached_read_timeout 60s;

上下文

http、server、location

memcached 定义从 gRPC 服务器读取响应的超时时间。超时间隔只在两次连续的读操作之间,而不是整个响应的传输过程。如果 memcached 服务器在此时间内没有发送任何内容,则连接关闭。

memcached_send_timeout

-

说明

语法

memcached_send_timeout time;

默认

memcached_send_timeout 60s;

上下文

http、server、location

设置将请求传输到 memcached 服务器的超时时间。超时间隔只在两次连续写入操作之间,而不是整个请求的传输过程。如果 memcached 服务器在此时间内没有收到任何内容,则连接将关闭。

内嵌变量

  • $memcached_key

    定义从 memcached 服务器获取响应的密钥

原文档

为了使这个参数起作用,通常需要以权限运行 nginx worker 进程。在 Linux 上,不需要指定 transparent 参数,工作进程会继承 master 进程的 CAP_NET_RAW 功能。此外,还要配置内核路由表来拦截来自 memcached 服务器的网络流量。

该指令还定义了与服务器进行通信的。error、timeout 和 invalid_response 的情况始终被视为失败尝试,即使它们没有在指令中指定。not_found 的情况永远不会被视为失败尝试。

将请求传递给下一个服务器可能受到和的限制。

限制尝试将请求传递到的次数。0 值表示关闭此限制。

如果域名解析为多个地址,则这些地址将以循环方式使用。另外,地址可以被指定为。

超级用户
服务器组
http://nginx.org/en/docs/http/ngx_http_memcached_module.html
指令
memcached_bind
memcached_buffer_size
memcached_connect_timeout
memcached_force_ranges
memcached_gzip_flag
memcached_next_upstream
memcached_next_upstream_timeout
memcached_next_upstream_tries
memcached_pass
memcached_read_timeout
memcached_send_timeout
内嵌变量
尝试次数
时间
下一个服务器
失败尝试