Created
August 6, 2020 11:58
-
-
Save isublimity/3d56066c07e65d5701833da8a309123d to your computer and use it in GitHub Desktop.
Nginx find in json deviceID for sharding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ngx.req.get_method() ~= "POST" then | |
return | |
end | |
-- read request body | |
ngx.req.read_body() | |
local data = ngx.req.get_body_data() | |
-- regexp | |
if data then | |
local f = string.match(data,ngx.var.MATH_REGEXP) | |
if f then | |
-- Set Var to Nginx | |
ngx.var.UUID = f; | |
end | |
end | |
-- Dump | |
ngx.say("Hello <b>world</b>! UUID = " .. ngx.var.UUID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#user www-data; | |
worker_processes 1; | |
worker_priority 1; | |
worker_rlimit_nofile 1000; | |
timer_resolution 100ms; | |
daemon off; | |
master_process on; | |
error_log /tmp/nginx-error.log; | |
#pid /var/run/nginx.pid; | |
events { | |
worker_connections 256; | |
} | |
http { | |
access_log /tmp/nginx-access.main.log; | |
error_log /tmp/nginx-error.main.log; | |
server { | |
set $UUID false; | |
location /hello { | |
set $MATH_REGEXP "\"deviceID\":\"([^\"]+)\""; | |
client_body_buffer_size 3M; | |
client_max_body_size 3M; | |
content_by_lua_file /tmp/nginx/jparseuuid.lua; | |
if ($UUID != false ) | |
{ | |
# use `upstream->hash $UUID`; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl http://localhost:8000/hello --data '{"username":"xyz","deviceID":"qew-ew-wee2qwe1","2323":"23"}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment