I need to do some time consuming processing on images that are served by NGinx, and I'd like to be able to respond quickly with partially processed images from cache.
Here are the steps of I'd like:
I'm using NGinx Lua module to process the images, and I'd like to be able to use proxy_cache functionality (LRU clean up, TTL, etc)
I have tried using proxy_pass, post_action and ngx.location.capture, but all of them wait for the subrequest to finish to close the connection. I've seen some solutions like Drupal Cache Warmer that issue a OS call to curl, but if possible I'd like not to do that.
This is my test case so far
server {
listen 8080;
location / {
rewrite_by_lua '
ngx.say(".")
--res = ngx.location.capture("/internal")
ngx.exit(ngx.OK)
';
proxy_pass http://127.0.0.1:8080/internal;
}
location /internal {
content_by_lua '
ngx.log(ngx.ERR, "before")
ngx.sleep(10)
ngx.say("Done")
ngx.log(ngx.ERR, "after")
ngx.exit(ngx.OK)
';
}
}
I have tried using post_action and ngx.location.capture, but both of them wait for the subrequest to finish to close the connection.
Take a look at ngx.eof()
documentation.
Update: http://wiki.nginx.org/HttpLuaModule#ngx.eof
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With