Asynchronous duplication request with nginx

How can I duplicate (or create and send) a request with the nginx web server. I can not use post_actionbecause it is a synchronous method. In addition, I compiled nginx with Lua support, but if I try to use http.requestwith ngx.thread.spawnor coroutine, I find that the request was executed synchronously. How to solve this?

location ~ /(.*)\.jpg {
    proxy_pass http://127.0.0.1:6081;
    access_by_lua_file '/var/m-system/stats.lua';
}

Lua script (c coroutine):

local http = require "socket.http"
local co = coroutine.create(function()
        http.request("http://10.10.1.1:81/log?action=view")
    end
)
coroutine.resume(co)
+4
source share
1 answer

ngx.thread.spawn does not work, only this code works:

access_by_lua '
    local socket = require "socket"
    local conn = socket.tcp()
    conn:connect("10.10.1.1", 2015)
    conn:send("GET /lua_async HTTP/1.1\\n\\n")
    conn:close()
';
+2
source

Source: https://habr.com/ru/post/1611105/


All Articles