If statement 如何在nginx的IF语句中使用AND运算符?

If statement 如何在nginx的IF语句中使用AND运算符?,if-statement,nginx,and-operator,If Statement,Nginx,And Operator,我正在尝试根据响应头缓存请求。 现在我想要的条件是,如果响应同时具有两个头客户端设备和客户端位置,那么响应应该缓存在nginx端 所以我试着用这个代码 if ($http_client_device && $http_clocation) { set $cache_key "$request_uri$http_client_device$http_client_location"; } proxy_cache_key $cache_key; 但nginx不允许这样 ng

我正在尝试根据响应头缓存请求。 现在我想要的条件是,如果响应同时具有两个头客户端设备和客户端位置,那么响应应该缓存在nginx端

所以我试着用这个代码

if ($http_client_device && $http_clocation) {
    set $cache_key "$request_uri$http_client_device$http_client_location";
}
proxy_cache_key $cache_key;
但nginx不允许这样 nginx:[emerg]在条件中出现意外的“&&”

不管怎么说,你要为这一个工作吗?
提前感谢

经过一整天的搜索,我找到了一个变通方法,参考了这个话题

一般来说,我的代码如下所示:

    if ($http_client_device) {
        set $temp_cache 1;
    }
    if ($http_client_location) {
        set $temp_cache 1$temp_cache;
    }
    if ($temp_cache = 11) {
        set $cache_key ...; 
    }
但仍然想知道在nginx中有没有更干净的方法和操作人员