caching - nginx not using proxy cache and cloudfront -


i'm trying cache static files on server, rather going 'upstream' server each time. upstream server happens cloudfront,

here nginx configuration:

nginx.conf http context:

proxy_cache_key "$scheme$host$request_uri"; proxy_cache_path /var/spool/nginx levels=1:1 keys_zone=oly_zone:1000m; proxy_cache_use_stale updating; proxy_cache_valid 200 301 302 10m; proxy_cache_valid 10s; proxy_cache oly_zone; 

website.conf:

location /gameimages/stock/ {   proxy_ignore_headers "set-cookie";   proxy_hide_header "set-cookie";   add_header x-proxy-cache $upstream_cache_status;   proxy_cache_valid 404 1s;   proxy_cache_valid 15d;   proxy_cache oly_zone;     proxy_pass http://d34sdfsfsadfasdfmhbsdafirsdfsdffelaut.cloudfront.net/; } 

i thought worked, example response header shows this:

accept-ranges:bytes age:11515 connection:keep-alive content-length:11577 content-type:image/jpeg date:mon, 08 aug 2016 19:25:16 gmt etag:"57a47349-2d39" last-modified:fri, 05 aug 2016 11:06:49 gmt server:nginx/1.4.1 via:1.1 3ba457b8dbcd4sadfsdfe93515e26caad.cloudfront.net (cloudfront) x-amz-cf-id:n0dlk5c28sdfsf5cvfskb3-t6prbfsxfepsdfasfuolw7sha1hjq== x-cache:hit cloudfront x-proxy-cache:hit 

it seems hitting both cloudfront , cache on server. doing wrong?

thanks,

michael

if issue still actual - have found solution. cloudfront should excluded assets loading path , s3 bucket should used directly data source.

solution: https://dpb587.me/blog/2015/06/20/using-nginx-to-reverse-proxy-and-cache-s3-objects.html

i case 1 line had added cache magic working:

    # use google dns     resolver 8.8.8.8; 

also selinux requres tuning prevent nginx (13: permission denied) errors:

sudo setsebool httpd_can_network_connect on -p sudo semanage permissive -a httpd_t 

Comments