Need to add expires header conditionally based on mime types

Simon Hönscheid mailinglisten at simonhoenscheid.de
Thu Jun 13 18:53:21 UTC 2013


Hi Silver,

this will fit your needs:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 7d;
}

Simon
Am 13.06.2013 14:26, schrieb Silver Moon:
> Hi
> 
> I need to add expires headers conditionally based on a certain mime type.
> For example add expires 7d to text/css
> 
> How to do this ?
> 
> So far I found that $sent_http_content_type contains the mime type that
> is send in http response. But its not possible to put it in a if
> directive and do expires
> either, 
> 
> if ($sent_http_content_type = "text/css")
> {
> expires 7d;
> }
> 
> will not work.
> 
> Also tried to create a map and try to hack around, but could not do it.
> 
> I cannot do on file based or specific directory location based because
> lots of css/js content is generated from php files dynamically. And
> there are multiple php files generating content.
> 
> I need a neat way to implement this, is it possible ?
> 
> -- 
> Silver
> 
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
> 



More information about the nginx mailing list