error_page not redirecting as expected

Maxim Khitrov max at
Fri Oct 26 12:49:26 UTC 2012


I'm sure it's something simple, but I don't know where the problem is
in the following configuration:

server {
	listen 80;
	root /path/to/webroot;

	error_page 404 /status/404;

	location / {
		try_files $uri @dynamic;

	location @dynamic {
		include fastcgi_params;
		fastcgi_pass unix:/tmp/myapp.sock;
		fastcgi_intercept_errors on;

I have some static files (css, js, etc.) under webroot that are served
by nginx. Everything else should be sent to @dynamic. If the initial
@dynamic request is answered with 404, I want nginx to make a second
request to @dynamic with the path set to /status/404.

What happens instead is that if the initial request receives a 404
response from the FastCGI responder, nginx serves the default 404 Not
Found page (not even the content returned by @dynamic) instead of
rewriting the request to /status/404. Opening /status/404 directly
works just fine.

Where did I make a mistake? There is nothing in the error log to give
me any hints.

- Max

More information about the nginx mailing list