nginx proxy_pass 基于请求方法是POST、PUT还是DELETE [英] nginx proxy_pass based on whether request method is POST, PUT or DELETE

查看:126
本文介绍了nginx proxy_pass 基于请求方法是POST、PUT还是DELETE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

http://wiki.nginx.org/HttpLuaModule 我看到有HTTP可以调用的方法常量',所以添加一个位置块是否正确:

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

谢谢

解决方案

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

server {地点/{# 这个proxy_pass 用于没有的请求# 匹配limit_exceptproxy_pass http://127.0.0.1:8080;limit_except PUT POST DELETE {# 对于 * 不是 * PUT、POST 或 DELETE 的请求,# 传递到 :9080proxy_pass http://127.0.0.1:9080;}}}

I have two iKaaro instances running on port 8080 and 9080, where the 9080 instance is Read only.

I am unsure how to use nginx for example if the request method is POST, PUT, DELETE then send to write instance (8080) else send to 9080 instance.

I have done something using the location using the regex, but this is not correct.

From http://wiki.nginx.org/HttpLuaModule i see that there is the 'HTTP method constants' which can be called, so is it correct to add a location block as:

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

Thanks

解决方案

I just did a quick test, and this worked for me:

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;
    }
  }
}

这篇关于nginx proxy_pass 基于请求方法是POST、PUT还是DELETE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆