-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnginx.conf
122 lines (95 loc) · 3.78 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
worker_processes 1;
error_log /dev/stderr debug;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
resolver 127.0.0.11 ipv6=off;
include mime.types;
default_type text/html;
lua_package_path "/etc/nginx/lua/?.lua;;";
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
# See Move default writable paths to a dedicated directory (#119)
# https://github.com/openresty/docker-openresty/issues/119
client_body_temp_path /var/run/openresty/nginx-client-body;
proxy_temp_path /var/run/openresty/nginx-proxy;
fastcgi_temp_path /var/run/openresty/nginx-fastcgi;
uwsgi_temp_path /var/run/openresty/nginx-uwsgi;
scgi_temp_path /var/run/openresty/nginx-scgi;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
charset utf-8;
source_charset utf-8;
init_worker_by_lua_block {
local uuid = require 'resty.jit-uuid'
uuid.seed()
}
server {
listen 9191;
server_name _;
# время жизни сессии в сек
set $queue_session_lifetime "20";
# максимальное количество сессий, которые могут быть пропущены на егов
set $queue_max_sessions "5";
# timeout к redis
set $queue_redis_timeout "1000";
# hostname или ip к redis
set $queue_redis_host "redis";
# port у redis
set $queue_redis_port "6379";
# название куки
set $queue_cookie_name "uuid";
# страница для пользователей
# если попадает в свободный слот, редиректит на целевую страницу
# если не попадает, то в очередь с отображением позиции в ней
location / {
content_by_lua_block {
local q = require "resty.queue"
local pos, err = q.getPosition()
local res
if pos <= 0 then
return ngx.redirect("http://google.com")
else
res = ngx.location.capture("/stub/" .. pos)
ngx.status = res.status
ngx.header = res.header
ngx.print(res.body)
end
}
}
# location по отображению заглушки
location ~* ^/stub/(.*?)$ {
internal;
set $position $1;
rewrite ^.*$ /index.html break;
root /var/www/public;
header_filter_by_lua_block { ngx.header.content_length = nil }
body_filter_by_lua_block {
ngx.arg[1] = ngx.arg[1]:gsub("__POSITION__", ngx.var.position)
}
}
# location по увеличению/уменшению global_offset
location /incr-offset {
content_by_lua_file /etc/nginx/lua/pages/incr-offset.lua;
}
# location с статистикой
location /stats {
content_by_lua_block {
local q = require "resty.queue"
local sessions, size, capacity, err = q.getStats()
ngx.say("available sessions: " .. sessions .. "\n" .. "current sessions in queue:" .. size .. "\n" .. "max active sessions: " .. capacity)
}
}
}
}