Nginx ngx_http_memcached_module模块基本指令整理

  categories:nginx  tags:  author:

原创文章,转载请指明出处并保留原文url地址

本文主要针对nginx的ngx_http_memcached_module模块做简单介绍,本文具体包括如下指令:memcached_bind,memcached_buffer_size,memcached_connect_timeout,memcached_gzip_flag,memcached_next_upstream,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;

}

}

Nginx原文:

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.

Example Configuration

server {

location / {

set            $memcached_key “$uri?$args”;

memcached_pass host:11211;

error_page     404 502 504 = @fallback;

}

location @fallback {

proxy_pass     http://backend;

}

}

1. memcached_bind

syntax: memcached_bind          address| off;
default:
context: http, server, location

强制从本地的某个ip地址连接到memcached服务器。这个参数能包括变量。Off参数取消来自前一个配置级别的memcached_bind指令的配置,允许系统自动分配本地地址进行连接。

Nginx原文:

Forces outgoing connections to a memcached server to originate from the specified local IP address. Value of the parameter can contain variables (1.3.12). The special value off (1.3.12) cancels the effect of the memcached_bind directive inherited from the previous configuration level, allowing the system to auto-assign local address.

2. memcached_buffer_size

syntax: memcached_buffer_size     size;
default: memcached_buffer_size 4k|8k;
context: http, server, location

设置用于缓存从memcached服务器接收响应buffer的大小。从服务器的相应同步传输到nginx。传回后立即进行接收处理。

Nginx原文:

Sets size of the buffer used for reading a response received from the memcached server. A response is passed to a client synchronously, immediately as it is received.

3. memcached_connect_timeout

syntax: memcached_connect_timeout  time;
default: memcached_connect_timeout 60s;
context: http, server, location

定义与memcached服务器建立连接的超时时间。这个时间通常不超过75秒

Nginx原文:

Defines a timeout for establishing a connection with the memcached server. It should be noted that this timeout cannot usually exceed 75 seconds.

4. memcached_gzip_flag

syntax: memcached_gzip_flag    flag;
default:
context: http, server, location

打开对memcached服务器响应中是否有 gzip标志的检查功能, 如果flag被设置则相应中“Content-Encoding”域将被设置为“gzip” 。

Nginx原文:

Enables the test for the flag presence in the memcached server response and sets the request header field “Content-Encoding” to “gzip” if the flag is set.

5. memcached_next_upstream

syntax: memcached_next_upstream error | timeout

| invalid_response | not_found | off …;

default: memcached_next_upstream error timeout;
context: http, server, location

指定在何种情况下把请求传递给下一个服务器:

超时(Error)

在与服务器建立连接,传递一个请求,或者读取相应头时发生错误。

超时

在与服务器建立连接,传递一个请求,或者读取相应头时超时。

invalid_response

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

not_found

响应服务器上找不到;

Off

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

应该认识到, 传递请求到下一个服务器仅仅在没有传输任何数据到客户端过程中才可能。 就是说当已经在传送数据给客户端过程中发生了错误,那么修正这个错误是不可能的。

Nginx原文:

Specifies in which cases a request should be passed to the next server:

error

an error occurred while establishing a connection with the server, passing it a request, or reading the response header;

timeout

a timeout has occurred while establishing a connection with the server, passing it a request, or reading the response header;

invalid_response

a server returned empty or invalid response;

not_found

a response was not found on the server;

off

disables passing a request to the next server.

It should be understood that passing a request to the next server is only possible if a client was not sent anything yet. That is, if an error or a timeout occurs in the middle of transferring a response, fixing this is impossible.

6. memcached_pass

syntax: memcached_pass       address;
default:
context: location, if in location

设置memcached服务器地址。地址可以指定为一个域名或ip地址,和端口,例如,

memcached_pass localhost:11211;

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

memcached_pass unix:/tmp/memcached.socket;

如果域名被解析为几个地址,他们将被循环使用。此外,一个地址可以被指定为一个服务器组。

Nginx原文:

Sets an address of the memcached server. An address can be specified as a domain name or an address, and a port, for example,

memcached_pass localhost:11211;

or as a UNIX-domain socket path:

memcached_pass unix:/tmp/memcached.socket;

If a domain name resolves to several addresses, all of them will be used in a round-robin fashion. In addition, an address can be specified as a server group.

7. memcached_read_timeout

syntax: memcached_read_timeout   time;
default: memcached_read_timeout 60s;
context: http, server, location

定义从memcached服务器读取响应超时时间。超时仅仅统计两个连续的读操作之间,不是整个响应传输时间。如果一个memcached服务器在此时间内不发送任何东西,连接关闭。

Nginx原文:

Defines a timeout for reading a response from the memcached server. A timeout is only set between two successive read operations, not for the transmission of the whole response. If a memcached server does not transmit anything within this time, a connection is closed.

8. memcached_send_timeout

syntax: memcached_send_timeout    time;
default: memcached_send_timeout  60s;
context: http, server, location

设置传输请求到memcached服务器超时时间。超时仅仅是两个连续的写操作之时间,不是整个响应传输时间。如果一个memcached服务器在此时间内不接受任何东西,连接关闭。

Nginx原文:

Sets a timeout for transmitting a request to the memcached server. A timeout is only set between two successive write operations, not for the transmission of the whole request. If a memcached server does not receive anything within this time, a connection is closed.



快乐成长 每天进步一点点      京ICP备18032580号-1