# Setting header for fastcgi response

**URL:** <https://www.ruby-forum.com/t/setting-header-for-fastcgi-response/224744>\
**Category:** NGINX\
**Created:** [November 24, 2012, 6:58am UTC](https://www.ruby-forum.com/t/setting-header-for-fastcgi-response/224744 "2012-11-24T06:58:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 24, 2012, 6:58am UTC](https://www.ruby-forum.com/t/setting-header-for-fastcgi-response/224744/1 "2012-11-24T06:58:49Z")

</div>

Hi,

In my nginx config, I have a virtual path (/foo), e.g.

location = /foo {  
expires 1h;  
add\_header Cache-Control “public”;  
}

This path does not exist, and it goes into the fcgi using

location / {  
try\_files $uri $uri/ /index.php?$args;  
}

location ~\* .php$ {  
…  
}

The problem is the 1st location block is adding 404 to every response  
even  
I can route the request to the backend.

E.g.

curl -v ‘[http://www.example.com/foo](http://www.example.com/foo)’

\< HTTP/1.1 404 Not Found  
bar ← actual output from backend, but why 404?

Any idea?

---

<div class="post-metadata">

**Author:** ![howard\_chen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bbce88/32.png) [@howard\_chen](https://www.ruby-forum.com/u/howard_chen)\
**Post date:** [November 24, 2012, 11:49am UTC](https://www.ruby-forum.com/t/setting-header-for-fastcgi-response/224744/2 "2012-11-24T11:49:09Z")

</div>

On Sat, Nov 24, 2012 at 01:58:16PM +0800, howard chen wrote:

Hi there,

in nginx, one request is handled in one location.

> location = /foo {  
> expires 1h;  
> add\_header Cache-Control “public”;  
> }

Your request for /foo should be handled in that location. It will,  
depending on the configuration that you haven’t shown, try to serve the  
file /usr/local/nginx/html/foo with a few extra http headers.

> This path does not exist, and it goes into the fcgi using
> 
> location / {  
> try\_files $uri $uri/ /index.php?$args;  
> }

The configuration you have shown does not indicate that that will  
happen.

(Unless, perhaps, you have something like an error\_page directive  
in place.)

> curl -v ‘[http://www.example.com/foo](http://www.example.com/foo)’
> 
> \< HTTP/1.1 404 Not Found  
> bar ← actual output from backend, but why 404?
> 
> Any idea?

Can you provide a config file that is enough to demonstrate what you  
are reporting?

Thanks,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
