我对nginx
和都很陌生lua
。我正在尝试按照本教程进行操作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/" -- 图片来源 local cache_dir = "cache/" -- 图片缓存位置
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。
这是终端中的错误
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"
我希望更有经验、更新颖的人能指出我做错的地方。谢谢。