小编zad*_*ops的帖子

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

我正在尝试根据响应标头缓存请求。现在我想要的条件是如果响应同时具有 2 个标头 client-device 和 client-location,那么响应应该缓存在 nginx 端

所以我尝试使用这段代码

if ($http_client_device && $http_clocation) {
    set $cache_key "$request_uri$http_client_device$http_client_location";
}
proxy_cache_key $cache_key;
Run Code Online (Sandbox Code Playgroud)

但 nginx 不允许 nginx: [emerg] 意外的“&&”条件...

无论如何要解决这个问题吗?提前致谢

if-statement nginx and-operator

23
推荐指数
2
解决办法
3万
查看次数

标签 统计

and-operator ×1

if-statement ×1

nginx ×1