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

Why is my nginx reverse-proxy not caching anything?

· 52CE 我爱测

I'm following this sample configuration from the Nginx docx. Reverse-proxying works fine except that it isn't caching results. Here is my nginx.conf: user http http; worker_processes 1; events { worker_connections 1024; } http { …

问题原文

原帖链接 · usermynut · CC BY-SA 3.0

I'm following this sample configuration from the Nginx docx. Reverse-proxying works fine except that it isn't caching results.

Here is my nginx.conf:

user http http;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    proxy_cache_path  /srv/http/my.site/cache  levels=1:2 keys_zone=STATIC:10m inactive=24h  max_size=1000m;
    proxy_temp_path   /srv/http/my.site/tmp;

    server {
        listen 8081;
        server_name my.site remote.host;

        location / {
            proxy_pass             http://remote.host;
            proxy_cache            STATIC;
            proxy_cache_valid      200 302 1d;
            proxy_cache_valid      404     1m;
        }
    }
}

Folder permissions are OK as far as I can tell:

ls -l /srv/http/my.site/
total 8
drwxr-xr-x 2 http http 4096 Dec 21 04:24 cache
drwxr-xr-x 2 http http 4096 Dec 21 04:24 tmp

已采纳解答

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

I'll post this as an answer because it's easier to format. Try this

proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; 
proxy_cache_valid 200 302 60h;
proxy_cache_valid any 60m;

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

资料来源与适用范围

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

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

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