Lua调味的Nginx重写或内部redirect周期

我对nginxlua都是新的。 我试图按照这个教程http://leafo.net/posts/creating_an_image_server.html#installation_requirements,但对于我的生活,我不能得到nginx.conf权利。

我已经检查了类似于这个问题的location其他问题,但我看不出我的代码有什么问题。

这里是nginx.conf

 error_log stderr notice; daemon off; events { } http { include /usr/local/openresty/nginx/conf/mime.types; server { listen 6789; lua_code_cache on; location @image_server { content_by_lua_file "serve_image.lua"; } location ~ ^/images/(?<size>[^/]+)/(?<path>.*\.(?<ext>[a-z_]*))$ { root cache; try_files /$path @image_server; } } } 

这是serve_image.lua代码

 local sig, size, path, ext = 

ngx.var.sig,ngx.var.size,ngx.var.path,ngx.var.ext local images_dir =“images /” – 其中图片来自本地cache_dir =“cache /” – 图片被caching

 local function return_not_found(msg) ngx.status = ngx.HTTP_NOT_FOUND ngx.header["Content-type"] = "text/html" ngx.say(msg or "not found") ngx.exit(0) end local source_fname = images_dir .. path ngx.log(ngx.STDERR, "->>>> " .. source_fname) -- make sure the file exists local file = io.open(source_fname) if not file then ngx.log(ngx.STDERR, "Couldn't find the input file" .. source_fname) return_not_found() end file:close() local dest_fname = cache_dir .. "/" .. size .. "/" .. path -- resize the image local magick = require("magick") magick.thumb(source_fname, size, dest_fname) ngx.exec(ngx.var.request_uri) 

当我运行服务器时,我得到一个代码500。

这是terminal中的错误

rewrite or internal redirection cycle while redirect to named location "@image_server", client: 127.0.0.1, server: , request: "GET /images/80x80/wow.png HTTP/1.1", host: "localhost:6789"

我希望更有经验和更新鲜的眼睛可以指出我做错了什么。 谢谢。