diff --git a/README.markdown b/README.markdown index 059b5b58..5c81a6d0 100644 --- a/README.markdown +++ b/README.markdown @@ -962,6 +962,42 @@ For instance, local res = ndk.set_var.set_escape_uri('a/b'); -- now res == 'a%2fb' +Trouble Shooting +================ + +HTTP 1.0 responses +------------------ + +Sometimes you may want to use nginx's ngx_proxy module to proxy requests to +another nginx machine which configured a location with `content_by_lua`. Because +`proxy_pass` only supports the HTTP 1.0 protocol, you have to pre-calculate +the length of your response body and set the `Content-Length` header before emitting +any data out. Here is a small example: + +On machine A: + + location /internal { + rewrite ^/internal/(.*) /lua/$1 break; + proxy_pass http://B; + } + +then on machine B: + + location = /lua/foo { + content_by_lua ' + data = "hello, world" + ngx.header.content_length = #data + ngx.print(data) + '; + } + +Then accessing machine A's /internal/foo using curl gives the result that we expect. + +But some caveats apply here: + +1. Always set the `Content-Length` header *before* calling `ngx.print()` or `ngx.say()`. +2. Only send out the response body data in a single call of `ngx.print()` or `ngx.say()`. + Performance ===========