每个用户代理的 nginx 缓存

Tui*_*lak 5 nginx

我目前使用 nginx 作为反向代理并启用缓存。

但是,主站点有两种不同的布局,具体取决于用户代理(移动与否)。

我试过类似的东西:

    # mobile users
    if ($http_user_agent ~* '(iPhone|iPod|mobile|Android|2.0\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile)') {
            set $iphone_request '1';
    }
    if ($iphone_request = '1') {
            proxy_cache        mobile;
    }
    if ($iphone_request = '') {
            proxy_cache        site;
    }
    proxy_cache_key    "$scheme://$host$request_uri";
    proxy_pass         http://real-site.tld;
Run Code Online (Sandbox Code Playgroud)

但是,nginx 给出了一个错误,指出不能在 if 结构中使用 proxy_cache。

根据浏览器的不同,还有其他方法可以从不同的缓存中提供服务吗?

谢谢,图因斯拉克

Ale*_*rov 3

为什么使用不同的缓存?也许基于$iphone_request变量定义缓存键就足够了?

proxy_cache_key "$iphone_request$uri";
Run Code Online (Sandbox Code Playgroud)