nginx+lua reverse proxy empty body

Bart van Deenen bart.vandeenen at spilgames.com
Tue Nov 27 10:28:40 UTC 2012


Hi all

I'm trying to do on-the-fly changes on the pages of a site using lua. 
I've set up a nginx reverse proxy, and some lua code to do the 
replacements, and I notice irreproducable (timing ?) situations where 
the proxied body that is passed to lua is empty. I know my code works in 
some cases, but I can't figure out what makes that it's not reliable.

nginx.conf:

worker_processes  1;
error_log logs/error.log debug;
events {
     worker_connections 1024;
}
http {
     server {
         client_body_in_single_buffer on;
         listen 9001;

         location / {
             proxy_pass http://www.spelletjes.nl:80;
             proxy_set_header X-Real-IP $remote_addr;
             body_filter_by_lua '

if ngx.arg[1] ~= "" then
     ngx.arg[1] = string.gsub(ngx.arg[1], "Speel", "NGINX")
else
     print(ngx.var.uri .. " has empty body" .. ngx.arg[1])
end
             ';
         }
     }
}
The problem I have basically that the ngx.arg[1] is an empty string 
(sometimes, timing dependent?) on url's that are definitely not empty.


So what am I doing wrong? I am using openresty 1.2.4.9 (nginx 1.2.4 + 
ngx_lua-0.7.5)

Typical message in logs/error.log:
   67 2012/11/26 14:53:59 [notice] 19291#0: *55 [lua] [string 
"body_filter_by_lua"]:7: / has empty body while             sending to 
client, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", 
upstream: "http://212.72.60.220:80/      ", host: "localhost:9001"


Thanks for answers

Bart



More information about the nginx mailing list