I did 2 tests. Both tests have one nginx as a proxy server and one nginx as an upstream server
Test#1 is WITH resty.limit.conn.
Test#2 is WITHOUT resty.limit.conn
Test#1 does NOT send any traffic to upstream. Is that expected? I would appreciate any help to understand why upstream is not receiving any traffic
. Thank you!
Test#1:
=====
- nginx.conf
upstream openx {
server 192.168.29.235:8002;
keepalive 16;
}
server {
listen 8002;
proxy_intercept_errors on;
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_connect_timeout 20ms;
proxy_send_timeout 20ms;
proxy_read_timeout 60ms;
access_by_lua_file /usr/local/openresty/nginx/conf/conf.d/lua/conn_openx.lua;
proxy_pass http://openx;
log_by_lua_file /usr/local/openresty/nginx/conf/conf.d/lua/log_openx.lua;
}
error_page 302 400 403 404 408 500 502 503 504 = /empty;
location /empty {
return 204;
}
}
- conn_openx.lua
local limit_conn = require "resty.limit.conn";
local lim, err = limit_conn.new("my_conn_store", 32, 10, 0.3);
if not lim then
ngx.log(ngx.ERR,
"failed to instantiate a resty.limit.conn object: ", err);
return ngx.exit(500);
end
local key = "openx";
local delay, err = lim:incoming(key, true);
if not delay then
if err == "rejected" then
return ngx.exit(503);
end
return ngx.exit(500);
end
if lim:is_committed() then
local ctx = ngx.ctx;
ctx.limit_conn = lim;
ctx.limit_conn_key = key;
ctx.limit_conn_delay = delay;
end
local conn = err;
if delay > 0 then
ngx.sleep(delay)
end
When I log on onto the server listed in the upstream connection (ssh 192.168.29.235) I see the following.
ubuntu@ip-192-168-29-235:/usr/local/openresty/nginx/conf/conf.d$ curl localhost:5001
Active connections: 1
server accepts handled requests
1 1 1 <================================ Why no traffic here?
Reading: 0 Writing: 1 Waiting: 0
Test#2 -- without the lua part --
- nginx.conf
upstream openx {
server 192.168.29.235:8002;
keepalive 16;
}
server {
listen 8002;
proxy_intercept_errors on;
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_connect_timeout 20ms;
proxy_send_timeout 20ms;
proxy_read_timeout 60ms;
proxy_pass http://openx;
}
error_page 302 400 403 404 408 500 502 503 504 = /empty;
location /empty {
return 204;
}
}
When I log on onto the server listed in the upstream connection (ssh 192.168.29.235) I see the following.
ubuntu@ip-192-168-29-235:/usr/local/openresty/nginx/conf/conf.d$ curl localhost:5001
Active connections: 135
server accepts handled requests
7820 7820 771016 <========================= This is expected
Reading: 0 Writing: 2 Waiting: 132