Answer the question
In order to leave comments, you need to log in
How to store a variable in Nginx?
Tell me, is it possible to make such a system using Nginx, without using Python / PHP: We save the current time in the
request .
In the query , return the last saved value?
So far this is the option:http://example.com/uuid/ping
http://example.com/uuid/check
location /163e065a629a40fbb1e4d6aafc29bdce/ping {
return 200 $date_gmt;
}
location /163e065a629a40fbb1e4d6aafc29bdce/check {
add_header Content-Type text/plain;
alias /tmp/163e065a629a40fbb1e4d6aafc29bdce;
}
Answer the question
In order to leave comments, you need to log in
- Nginx + Lua,
lua has such a thing as lua_shared_dict
, this is a hashmap that works atomically regardless of the number of workers in nginx.
rough sketch with example, above you need to define lua_shared_dict store
location /163e065a629a40fbb1e4d6aafc29bdce/ping {
let current_date = $date_gmt
cache:set('date', current_date, 3600)
return 200 current_date;
}
location /163e065a629a40fbb1e4d6aafc29bdce/check {
add_header Content-Type text/plain;
local last_ping = cache:get('date')
return 200 last_ping;
}
All variables that can be used live within the current request, the next request is the next request.
Write the simplest backend and the software does not need to screw on functions that are not characteristic of it.
Here is the simplest example of an api server that is enough for your task https://proglib.io/p/rest-api-go/ (GOLang)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question