非常教程

Nginx参考手册

ngx_http_memcached_module

ngx_http_memcached_module

  • 示例配置
  • 指令
  • 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
  • 嵌入式变量

ngx_http_memcached_module模块用于从memcached服务器获取响应。密钥在$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 address transparent | off;

默认:

语境:

http,服务器,位置

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

transparent参数(1.11.0)允许分布式缓存服务器传出连接从一个非本地的IP地址发起,例如,来自客户端的实际IP地址:

memcached_bind $remote_addr transparent;

为了使此参数起作用,需要以超级用户权限运行nginx工作进程,并配置内核路由表以拦截来自memcached服务器的网络流量。

句法:

memcached_buffer_size size;

默认:

memcached_buffer_size 4k | 8k;

语境:

http,服务器,位置

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

句法:

memcached_connect_timeout时间;

默认:

memcached_connect_timeout 60s;

语境:

http,服务器,位置

定义与memcached服务器建立连接的超时时间。应该指出的是,这个超时通常不能超过75秒。

句法:

memcached_force_ranges开启| 关闭;

默认:

memcached_force_ranges off;

语境:

http,服务器,位置

无论这些响应中的“接受范围”字段如何,都可以对来自memcached服务器的缓存和未缓存的响应启用字节范围支持。

句法:

memcached_gzip_flag标志;

默认:

语境:

http,服务器,位置

启用对flagmemcached服务器响应中状态的测试,并在标志设置时将“ Content-Encoding”响应标题字段设置为“ gzip”。

句法:

memcached_next_upstream错误| 超时| invalid_response | not_found | 关闭...;

默认:

memcached_next_upstream错误超时;

语境:

http,服务器,位置

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

error在与服务器建立连接,传递请求或读取响应头时发生错误; timeout在与服务器建立连接,传递请求或读取响应头时发生超时; invalid_response服务器返回了空的或无效的响应; not_found在服务器上未找到响应; off禁用将请求传递给下一个服务器。

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

该指令还定义了与服务器进行通信的不成功尝试。 即使未在指令中指定错误,超时和invalid_response的情况,也总是被视为不成功尝试。 not_found的情况永远不会被视为不成功的尝试。

将请求传递给下一台服务器可能受到尝试次数和时间的限制。

句法:

memcached_next_upstream_timeout时间;

默认:

memcached_next_upstream_timeout 0;

语境:

http,服务器,位置

限制请求可以传递到下一个服务器的时间。该0值将关闭此限制。

句法:

memcached_next_upstream_tries数字;

默认:

memcached_next_upstream_tries 0;

语境:

http,服务器,位置

限制将请求传递到下一个服务器的可能尝试次数。该0值将关闭此限制。

句法:

memcached_pa​​ss地址;

默认:

语境:

位置,如果在位置

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

memcached_pass localhost:11211;

或者作为UNIX域套接字路径:

memcached_pass unix:/tmp/memcached.socket;

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

句法:

memcached_read_timeout时间;

默认:

memcached_read_timeout 60s;

语境:

http,服务器,位置

定义从memcached服务器读取响应的超时。超时只在两次连续的读操作之间设置,而不是用于传输整个响应。如果memcached服务器在此时间内没有传输任何内容,则连接将被关闭。

句法:

memcached_send_timeout时间;

默认:

memcached_send_timeout 60s;

语境:

http,服务器,位置

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

嵌入式变量

$memcached_key 定义从memcached服务器获取响应的键值。

ngx_http_memcached_module
Nginx

Nginx是一款轻量级的 Web 服务器/反向代理服务器及电子邮件代理服务器,可在 BSD-like 协议下发行。其特点是占有内存少,并发能力强。

主页 https://nginx.org/
源码 http://hg.nginx.org/nginx
发布版本 1.13.6

Nginx目录

1.指南 | Guides
2.核心 | Core
3.ngx_google_perftools_module
4.ngx_http_access_module
5.ngx_http_addition_module
6.ngx_http_api_module
7.ngx_http_auth_basic_module
8.ngx_http_auth_jwt_module
9.ngx_http_auth_request_module
10.ngx_http_autoindex_module
11.ngx_http_browser_module
12.ngx_http_charset_module
13.ngx_http_core_module
14.ngx_http_dav_module
15.ngx_http_empty_gif_module
16.ngx_http_f4f_module
17.ngx_http_fastcgi_module
18.ngx_http_flv_module
19.ngx_http_geoip_module
20.ngx_http_geo_module
21.ngx_http_gunzip_module
22.ngx_http_gzip_module
23.ngx_http_gzip_static_module
24.ngx_http_headers_module
25.ngx_http_hls_module
26.ngx_http_image_filter_module
27.ngx_http_index_module
28.ngx_http_js_module
29.ngx_http_keyval_module
30.ngx_http_limit_conn_module
31.ngx_http_limit_req_module
32.ngx_http_log_module
33.ngx_http_map_module
34.ngx_http_memcached_module
35.ngx_http_mirror_module
36.ngx_http_mp4_module
37.ngx_http_perl_module
38.ngx_http_proxy_module
39.ngx_http_random_index_module
40.ngx_http_realip_module
41.ngx_http_referer_module
42.ngx_http_rewrite_module
43.ngx_http_scgi_module
44.ngx_http_secure_link_module
45.ngx_http_session_log_module
46.ngx_http_slice_module
47.ngx_http_spdy_module
48.ngx_http_split_clients_module
49.ngx_http_ssi_module
50.ngx_http_ssl_module
51.ngx_http_status_module
52.ngx_http_stub_status_module
53.ngx_http_sub_module
54.ngx_http_upstream_conf_module
55.ngx_http_upstream_hc_module
56.ngx_http_upstream_module
57.ngx_http_userid_module
58.ngx_http_uwsgi_module
59.ngx_http_v2_module
60.ngx_http_xslt_module
61.ngx_mail_auth_http_module
62.ngx_mail_core_module
63.ngx_mail_imap_module
64.ngx_mail_pop3_module
65.ngx_mail_proxy_module
66.ngx_mail_smtp_module
67.ngx_mail_ssl_module
68.ngx_stream_access_module
69.ngx_stream_core_module
70.ngx_stream_geoip_module
71.ngx_stream_geo_module
72.ngx_stream_js_module
73.ngx_stream_limit_conn_module
74.ngx_stream_log_module
75.ngx_stream_map_module
76.ngx_stream_proxy_module
77.ngx_stream_realip_module
78.ngx_stream_return_module
79.ngx_stream_split_clients_module
80.ngx_stream_ssl_module
81.ngx_stream_ssl_preread_module
82.ngx_stream_upstream_hc_module
83.ngx_stream_upstream_module