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 ?
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
this is not sufficient.
in my application for example, js, css and images are generated
dynamically
from php scripts. and there are multiple scripts to generate such
content.
therefore i need mime based expire headers.
On Fri, Jun 14, 2013 at 12:23 AM, Simon Hnscheid <
Are they presented as .js, .css etc to the client browser?
If so, then this is sufficient.
Steve
On Fri, 2013-06-14 at 08:28 +0530, Silver Moon wrote:
}
>
> }
> there are multiple php files generating content.
> [email protected]
–
Silver
nginx mailing list
[email protected]
nginx Info Page
–
Steve H. BSc(Hons) MNZCS
Linkedin: http://www.linkedin.com/in/steveholdoway
Skype: sholdowa
yes, i could send out headers from php itself
but mime based header generation in the webserver itself would make
things
easier.
so finally it is impossible to achieve that ?
From what you describe I do think the suggested nginx config is
enough…
However maybe you’re looking for something like this:
Not really sure if it suits you’re needs, but It seems this is what
you’re looking for.
You can also find more info on mime type here:
http://wiki.nginx.org/HttpCoreModule#types
Hope this helps,
Mike
If you handle your js, css and images by php scripts you can use header
function to send out Expires and Cache-Control directives
example:
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
the
putting $upstream_http_content_type or $sent_http_content_type or
$content_type inside “if” does not work.
i wish someone could test and provide a working example.
none of the samples shown in the stackoverflow post work.
i tested enough and found that only $sent_http_content_type contains
the
http response Content-type
and that can be tested like this
add_header TEST $sent_http_content_type
however putting that inside an if and trying to add further headers
inside
that if will not work
i opened a ticket in trac and they said that it does not work like that
however no one confirms if it is strictly possible or impossible.
If you use the Lua embedded module you can do that AFAICT.
Le 14 juin 2013 05:42, “Silver Moon” [email protected] a crit :