Setting custom response headers

ehudros2 nginx-forum at
Wed Jun 3 13:36:50 MSD 2009

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;

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? 
Thanks :)

Posted at Nginx Forum:,2598,2598#msg-2598

More information about the nginx mailing list