来自 Tarantool + Nginx 的自定义响应

Custom response from Tarantool + Nginx

有实例:DMZ 中的 Nginx,TNT_nginx_upstream_module + Tarantool Cartridge 作为 API 服务器。
当我得到好的回应时 - 200 OK + JSON with data
如何设置其他响应?

Tarantool Nginx 上游模块设计为遵循 JSON RPC,而不是通用 HTTP。有一种方法可以 return 任意结果,使用 location 部分中的 rewrite_by_lua。它看起来像这样:

location /api {
  default_type application/json;
  rewrite_by_lua '
    ...
  ';
}

我没有在这里粘贴完整的代码段,因为它很长。你可以查一下here.

一般来说,如果您想要一个通用的 HTTP API,我也建议您不要使用提到的上游模块。最好使用HTTP server module written in Lua, and use Nginx as a regular reverse proxy. As a bonus, the Lua HTTP server comes on board of the cartridge模块。