Setting custom response headers

Igor Sysoev is at
Wed Jun 3 15:37:41 MSD 2009

On Wed, Jun 03, 2009 at 05:36:50AM -0400, ehudros2 wrote:

> Hi all,
> I'm trying something that I though should be quite simple but turns out it isn't...
> I have a rails app and want all static assets with a timestamp query string to be sent with a custom response header called "User-Expires", instead of the regular "expires" directive.
> I'm coming from apache, and I'm not sure if proxy_set_header is what I'm looking for or not.
> In any case, I'm using the following code:
>   if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png|swf)\?[0-9]+$") {
>                        expires 30d;
>                        proxy_set_header User-Expires 300d;
>                        break;
>                 }
> And I'm getting the following error: 
>   28514#0: "proxy_set_header" directive is not allowed here
> I tried moving it to the top (right under all my other proxy_set_headers and it didn't return an error but also did not seem to set the header.
> I'm totally confused here - why is it called proxy_set_header when I'm not even using a proxy - i'm just returning the static asset without proxying anything to mongrel. Am I totally missing something here? 

I do not know why do use proxy_set_header if you are not even using a proxy.

Probably, you need

    location ~* \.(ico|css|js|gif|jpe?g|png|swf)$ {
        if ($args ~ ^\d+$) {
            add_header  User-Expires 300d;

Igor Sysoev

More information about the nginx mailing list