nginx+lua reverse proxy empty body

Bart van Deenen bart.vandeenen at
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.


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_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")
     print(ngx.var.uri .. " has empty body" .. ngx.arg[1])
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 (nginx 1.2.4 + 

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:, server: , request: "GET / HTTP/1.1", 
upstream: "      ", host: "localhost:9001"

Thanks for answers


More information about the nginx mailing list