Nginx代理传递基于http方法

时间:2016-11-17 08:23:49

标签: nginx

是否可以过滤来自OPTIONS的{​​{1}}来电并将其重定向到其他地方?试过这个配置但没有用:

location

1 个答案:

答案 0 :(得分:2)

有几种方法可以实现。在我看来,最简单的是map指令:

upstream some_backend {
    server example.com;
}

upstream another_backend {
    server anotherurl.com;
}

map $request_method $upstream {
    default some_backend;
    OPTIONS another_backend;
}

server {
    ...
    location /example/ {
        ...
        proxy_pass http://$upstream;
        ...
    }
    ...
}

使用upstreams不是强制性的,但建议使用。在大多数情况下,它将使您的配置更易于阅读,维护和扩展。不过,如果您希望省略upstream块并直接在map块中编写主机,则配置仍然有效:

map $request_method $upstream {
    default example.com;
    OPTIONS anotherurl.com;
}
相关问题