,
1. 499
HTTP 499 - nginx, (http://lxr.nginx.org/source/src/http/ngx_http_request.h#0120)
,
nc -k -l 172.17.0.6 172.17.0.6:11211
- , Ctrl + C -
2.
, nginx memcached . memcached, ( error_log ... info
).
, , nginx memcached, , .
http://nginx.org/en/docs/http/ngx_http_memcached_module.html#memcached_bind
-b telnet, , memcached telnet
3. nginx memcached ,
Nginx memcached
(http://nginx.org/en/docs/http/ngx_http_memcached_module.html):
ngx_http_memcached_module memcached. $memcached_key. memcached , Nginx.
4.
, .
nginx upstream .
, memcached .
, memcached_next_upstream not_found
, , . , 2 , , 20
memcached - = > ,
5.
10 - , . , , , 2 memcached -vv, , (memcached -p 11211 -U o -vv
), - f , , .
6.
nginx config:
https http/1.1 , .
upstream http_memcached {
server 127.0.0.1:11211;
server 127.0.0.1:11212;
}
upstream remote {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name server.lan;
access_log /var/log/nginx/server.access.log;
error_log /var/log/nginx/server.error.log info;
location / {
set $memcached_key "$uri?$args";
memcached_next_upstream not_found;
memcached_pass http_memcached;
error_page 404 = @remote;
}
location @remote {
internal;
access_log /var/log/nginx/server.fallback.access.log;
proxy_pass http://remote;
proxy_set_header Connection "";
}
}
server.py
(python):
from random import randint
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello: {}\n'.format(randint(1, 100000))
( )
FLASK_APP=server.py [flask][2] run -p 8080
memcached:
$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set /? 0 900 5
cache
STORED
quit
Connection closed by foreign host.
:
, ,
$ curl http://server.lan && echo
cache
$ curl http://server.lan && echo
cache
$ curl http://server.lan && echo
cache
, server.py
$ curl http://server.lan/?q=1 && echo
Hello: 32337
:
2
memcached -p 11211 -U o -vv
memcached -p 11212 -U o -vv