Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous duplication request with nginx

Tags:

nginx

lua

How I can duplicate (or create and send) a request with the nginx web server. I can't use post_action, because it is a synchronous method. Also, I compiled nginx with Lua support, but if I try to use http.request with ngx.thread.spawn or coroutine, I find the request has been executed synchronously. How do I solve this?

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

Lua script (with 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)
like image 853
Dmitry Avatar asked Oct 20 '22 00:10

Dmitry


1 Answers

ngx.thread.spawn not working, only this code worked:

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()
';
like image 105
Dmitry Avatar answered Oct 22 '22 22:10

Dmitry