nginx proxy_pass基于请求方法是POST,PUT还是DELETE [英] nginx proxy_pass based on whether request method is POST, PUT or DELETE
问题描述
我有两个在端口8080和9080上运行的 iKaaro 实例,其中9080实例为只读.>
例如,如果请求方法是POST,PUT,DELETE,然后发送到写入实例(8080),否则发送到9080实例,我不确定如何使用nginx.
我使用正则表达式在位置上做了一些操作,但这是不正确的.
从 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 {
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;
}
}
}
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屋!