大网数据广告活动
服务器运维问答

NGINX - Caching not working - Always MISS

· 52CE 我爱测

I'm currently working on enabling caching on a NGINX (Reverse Proxy). With this configuration, the value of X-Proxy-Cache is always MISS . My current conf ( in /etc/nginx/conf.d ) : proxy_cache_path /data/nginx/cache/MON_URL leve…

问题原文

原帖链接 · Quentin Rey · CC BY-SA 4.0

I'm currently working on enabling caching on a NGINX (Reverse Proxy).

With this configuration, the value of X-Proxy-Cache is always MISS.

My current conf (in /etc/nginx/conf.d) :

proxy_cache_path /data/nginx/cache/MON_URL levels=1:2 keys_zone=MY_ZONE:8m max_size=1000m inactive=24h;

upstream opera {
    server MY_SERVER_IP:443;
}

server {
    listen 80;
    server_name MON_URL www.MON_URL;
    return 301 https://MON_URL$request_uri;

}

server {
    listen 443 ssl;
    server_name www.MON_URL;
    return 301 $scheme://MON_URL$request_uri;
}

server {
    listen 443 ssl;
    server_name MON_URL;

    location / {
        proxy_pass https://opera/;
        rewrite ^/$ /OPERA/ last;
        proxy_cache MY_ZONE;
        proxy_cache_valid any 24h;
        proxy_set_header Host $host;
        add_header X-Proxy-Cache $upstream_cache_status;
    }

    location /robots.txt {
        return 200 "User-agent: *\nDisallow: /";
    }
}

I tried different configurations based on the doc or different posts here, without success.

I hope someone could help me move forward on this problem! Thanks in advance !

社区高分解答

原帖链接 · Juraj · CC BY-SA 4.0

I had the same problem, in my case it was this line:

proxy_buffering    off;

It's also mentioned in the "common mistakes" article on their blog:
https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#proxy_buffering-off

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-06-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。