I am utilizing Nginx's proxy_cache module for caching but have noticed the page does not cache immediately. The content is very dynamic and each page load produces a different layout, I am trying to cache the layout for an hour.
Nginx only seems to cache the page after hitting it with multiple requests quickly. Here is my config.
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=1000m; #caching
proxy_temp_path /var/tmp; #caching
proxy_cache_valid 404 500 1m;
proxy_cache_valid 200 60m;
proxy_cache_min_uses 1;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
upstream staging {
server 127.0.0.1:1337;
server 127.0.0.1:7331;
}
server {
listen 0.0.0.0:80;
server_name dev.example.com;
access_log /var/log/nginx/dev.example.log;
error_log /var/log/nginx/dev.example.error.log debug; log_subrequest on;
location ~ ^/(images/|scripts/|styles/|robots.txt|humans.txt|favicon.ico) { #caching
root /home/example/app/website/public;
access_log off;
expires max;
}
location /ssi { #Our serverside includes
proxy_pass http://staging;
}
location / {
ssi on;
#auth_basic "Restricted";
#auth_basic_user_file /etc/nginx/.htpasswd;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_cache one; #caching
proxy_cache_key sfs$request_uri$scheme; #caching
proxy_http_version 1.1;
proxy_pass http://staging/; #points to the upstream staging
}
}
server {
listen 0.0.0.0:80;
server_name static.example.com;
location ~ ^/(images/|scripts/|styles/|robots.txt|humans.txt|favicon.ico) { #caching
add_header Access-Control-Allow-Origin *.example.com;
root /home/example/app/website/public;
access_log off;
expires max;
}
location / {
return 404;
}
}
Set-Cookie
,Expires
orX-Accel-Expires
headers?