3

Our stack is nginx - gunicorn - mezzanine (django cms) running on an EC2 instance. Everything works, but I can't seem to enable nginx proxy_cache. Here is my minimal config:

upstream %(proj_name)s {
    server 127.0.0.1:%(gunicorn_port)s;
}

proxy_cache_path /cache keys_zone=bravo:10m;

server {
    listen 80;
    listen 443;
    server_name %(live_host)s;
    client_max_body_size 100M;
    keepalive_timeout 15;

    location /static/ {
        expires 1M;
        access_log off;
        add_header Cache-Control "public";
        root %(proj_path)s;
    }

    location / {
        expires 1M;
        add_header X-Proxy-Cache $upstream_cache_status;
        proxy_cache bravo;
        proxy_ignore_headers Cache-Control Expires Set-Cookie;

        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_pass http://%(proj_name)s;
    }
}

Sample response:

HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 07 Jan 2015 03:43:47 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Vary: Cookie, Accept-Language
Content-Language: en
Expires: Fri, 06 Feb 2015 03:43:47 GMT
Cache-Control: max-age=2592000
X-Proxy-Cache: MISS
Content-Encoding: gzip

I have mezzanine cache middleware enabled and it is returning responses with Set-Cookie headers, but proxy_ignore_headers should ignore that.

I did chmod 777 on proxy_cache_path dir (/cache) so it shouldn't be a permissions issue.

Error logging is enabled but has produced nothing.

proxy_cache_path continues to remain completely empty...

Why is nginx not caching anything with this config?

Robert Carter Mills
  • 793
  • 1
  • 9
  • 19

0 Answers0