Kodunuzun bir sorunları vardır. böylece "diğer vaka" Başka ve birileri tarafından belirtildiği gibi
"($ request_body ~ * (. *))" "
Daha da önemlisi, kullandığı sonuç her zaman her şeye uyar asla proxy_pass "with" "klasik olarak kötüyse". http://wiki.nginx.org/IfIsEvil.
location ~ \.php$ {
rewrite_by_lua '
ngx.req.read_body()
local match = ngx.re.match(ngx.var.request_body, "target")
if match then
ngx.exec("@proxy");
else
ngx.exec("@other_case");
end
';
}
location @proxy {
# test.proxy stuff
...
}
location @other_case {
# other_case stuff
...
}
Sen
https://github.com/chaoslawful/lua-nginx-module/tags de ngx_lua alabilirsiniz ..., istediğini elde 3. parti ngx_lua modülünü (yukarıdaki v0.3.1rc24 ve) kullanın.
PS. Nuax yeniden yazma direktiflerinden sonra lua ile yeniden yazmanın akılda tutulması gerektiğini aklınızda bulundurun, böylece başka bir durumda bu tür direktifler koyarsanız, bunlar önce idam edilecek ve eğleneceksiniz.
Tüm yeniden yazmalarınızı, tutarlı sonuçlar için lua bağlamında yeniden yazmanız gerekir. "Diğer durum" için "if ..else..end" düzenlemesinin nedeni budur.
Nefesini tutmayın bu uzun versiyon
location ~ \.php$ {
rewrite_by_lua '
--request body only available for POST requests
if ngx.var.request_method == "POST"
-- Try to read in request body
ngx.req.read_body()
-- Try to load request body data to a variable
local req_body = ngx.req.get_body_data()
if not req_body then
-- If empty, try to get buffered file name
local req_body_file_name = ngx.req.get_body_file()
--[[If the file had been buffered, open it,
read contents to our variable and close]]
if req_body_file_name then
file = io.open(req_body_file_name)
req_body = file:read("*a")
file:close()
end
end
-- If we got request body data, test for our text
if req_body then
local match = ngx.re.match(req_body, "target")
if match then
-- If we got a match, redirect to @proxy
ngx.exec("@proxy")
else
-- If no match, redirect to @other_case
ngx.exec("@other_case")
end
end
else
-- Pass non "POST" requests to @other_case
ngx.exec("@other_case")
end
';
}
gerekebilir. Sayılırsa, http://wiki.nginx.org/HttpCoreModule#client_body_in_single_buffer adresini değiştirebilirsiniz. Ama ben istek beden – rzab
eşleştirebilirsiniz sanmıyorum Şimdi sorunun regexp içinde olmadığını anlıyorum, ama $ request_body bu noktada boş gibi görünüyor, hatta read_request_body yöntemi sağlayan echo modülünü denedim, ama hala boş :( – sharpner
Tam olarak: http://wiki.nginx.org/EmbeddedPerlModule doc, nginx bir geçici dosyaya karşılık olarak bellekte gövdeyi tuttuğunda $ request_body öğesinin kullanılabilir olduğunu belirtiyor. client_max_body_size yardımıyla body_ size_ size_body_buffer_size kullanarak buffer için yeterli boyut atabilir ve "client_max_body_size değerini client_body_buffer_size değerinden daha düşük bir değere ayarlamanız önerilir. – rzab