lua - nginx proxy_pass 基于请求方法是 POST、PUT 还是 DELETE

标签 lua nginx

我有两个iKaaro在端口 8080 和 9080 上运行的实例,其中 9080 实例是只读的。

我不确定如何使用 nginx,例如,如果请求方法是 POST、PUT、DELETE,则发送到写入实例 (8080),否则发送到 9080 实例。

我已经使用正则表达式使用位置做了一些事情,但这不正确。

来自http://wiki.nginx.org/HttpLuaModule我看到有可以调用的“HTTP 方法常量”,那么添加位置 block 是否正确:

location ~* "(ngx.HTTP_POST|ngx.HTTP_DELETE|ngx.HTTP_PUT)" {
    proxy_pass http://127.0.0.1:8080;

谢谢

最佳答案

我刚刚做了一个快速测试,这对我有用:

server {
  location / {
    # This proxy_pass is used for requests that don't
    # match the limit_except
    proxy_pass http://127.0.0.1:8080;

    limit_except PUT POST DELETE {
      # For requests that *aren't* a PUT, POST, or DELETE,
      # pass to :9080
      proxy_pass http://127.0.0.1:9080;
    }
  }
}

关于lua - nginx proxy_pass 基于请求方法是 POST、PUT 还是 DELETE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8591600/

相关文章:

ios - 全局 favicon.ico 和 iOS 图标

nginx 反向代理的 SSL 握手问题

django - 使用Nginx和Gunicorn运行多个Django项目

Nginx 重载配置最佳实践

module - 所需脚本中的代码 "local a = (...);"是什么意思?

sockets - 如何实时接收来自服务器的消息

lua - 从 Aerospike 读取记录列表

c++ - 在 Cmake 中静态链接 Lua

c++ - LuaPlus 从 C++ 操作表

php - UTF-8 不工作 nginx