Problem with Nginx returning correct content, but with 404

Maxim Dounin mdounin at
Thu Jan 20 19:56:14 MSK 2011


On Thu, Jan 20, 2011 at 11:23:17AM -0500, austinmills wrote:

> We have a setup where we have requests coming into a cache server which
> is in front of an app server. The requests hit nginx on the cache
> server, which makes the request to a process running on the cache
> server. That process will return either the requested content (if in the
> cache) or a 404. In the case of a 404, nginx on the cache server should
> then turn around and make the same request to the app server. The app
> server serves the content, and then nginx on the app server should turn
> around and return the response to the client.
> The problem we are seeing is that this works fine for requests of the
> form /admin/fan_pages, but when requesting css or png content (like
> /stylesheets/common.css , or /images/admin/fan_pages/refresh.png ), it
> is returning the correct content, but with a 404 code. In this case, the
> local process on the cache server is returning a 404, the nginx on the
> cache server is requesting the page from the app server (which returns
> the page with a 200), but then the cache server is turning around and
> serving the correct content to the client with a 404. 
> Anybody have any ideas on how/why this is happening? I'll include config
> files and output below. If there's a simpler or better setup to
> accomplish what we're trying to do, I'm happy to try that as well.

Request to /stylesheets/common.css will generate 404 as long 
as you don't have static file on disk, as it's matched by this 
location in your config:

> # set Expire header on assets: see
> location ~ ^/(images|javascripts|stylesheets)/ {
>   expires 10y;
> }

You have 404 error_page set without overwriting status code:

> error_page 404 /404.html;

I.e. 404 code will be preserved regardless of future processing.  
This explains 404 status code.

Future processing will happen here:

>   location / {
>     proxy_next_upstream http_404 http_500 http_502 http_503 http_504 error timeout;
>     proxy_pass http://switching_backend;
>   }

As proxy_pass without uri component is used, it will preserve 
original request uri when asking backend.  This explains correct 

Maxim Dounin

More information about the nginx mailing list