I have a dynamic content controller in CodeIgniter that pulls images from GridFS. The server is running nginx and I am trying to set the cache control headers in my nginx config to cache the images served by this dynamic content controller for 7 days. I have the config set correctly in my nginx config, but I am getting 404 headers from nginx because the files do not physically exist on the server.
My cache control directive is as follows:
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 7d;
log_not_found off;
}
log_not_found helps keep nginx from logging the 404 error, but the headers that are sent to the browser are still 404 errors. I tried setting the headers manually via php's "header" function, but because nginx is using php-fpm, it was doing some weird stuff.
Can anyone point me in the correct direction on how to get my cache control headers set up properly for this situation? Thanks everyone =)
UPDATE:
I changed my nginx conf with a special location for all my static files and my dynamic controller.
location ~ ^/(dres|js|css|art)/ {
access_log off;
expires 7d;
add_header Cache-Control public;
try_files $uri $uri/ /index.php?$args;
}
Nginx is setting the correct expires headers on the static files, but I cannot for the life of me get fastcgi and nginx to output the expires headers for the dynamically output images. I must be missing something in my fastcgi config to allow expiration headers when serving php files.