There's a similar question but solution there doesn't work for me.
We have nginx and uWSGI ad backend. We need nginx to cache the backend response according to what is in the response header.
For example, I run curl -I https://example.com/api/project_data/
. Using tcpdump
I see the backend responds:
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept, Accept-Language, Origin
Allow: GET, HEAD, OPTIONS
Cache-Control: public, max-age=3600
X-Request-ID: 6aa...0d99
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Set-Cookie: longterm_session=45c6...67; Domain=example.com;
Nevertheless, the response isn't cached and nginx knoks to the backend every time the request received.
The nginx config:
http {
uwsgi_cache_path /var/local/nginx_cache levels=2:2 use_temp_path=off inactive=1h keys_zone=mycache:20m ;
....
server {
....
uwsgi_cache mycache;
uwsgi_cache_key "$request_method$request_uri";
location /api/project_data/ {
add_header X-Cache $upstream_cache_status;
add_header Pragma "public";
uwsgi_pass 127.0.0.1:49002;
include uwsgi_params;
uwsgi_cache mycache;
uwsgi_cache_key "$request_method$request_uri";
}
I duplicated uwsgi_cache
just to be on the safe side because afaik some directives are not inherited into location
. Also, there's x-cache: MISS
in the response nginx sends to the client.
What am I doing wrong?