2

I set up custom error pages in nginx with fastCGI for PHP like this way and it works:

root <FOLDER>;
error_page 404 /error.php?404;
location = /error.php {
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass  127.0.0.1:1234;
    root  <FOLDER>;
}

But since I have one error.php for every HTTP error codes, I wanted to set up in a general form. The problem is that I don't know if nginx provide the error code to be passed by GET to error.php

I am looking for something like:

root <FOLDER>;
error_page 500 501 502 401 402 403 404 /error.php?NGINX_ERROR_CODE;
location = /error.php {
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass  127.0.0.1:1234;
    root  <FOLDER>;
}

The problem is NGINX_ERROR_CODE which I don't know if it provides such a thing to set up general error_page handler.

Is it any way?

1 Answer 1

1

Googling around, it doesn't initially appear that there's a var for it.

You can, however, set multiple error page directives.

error_page 401 /error.php?e=401;
error_page 402 /error.php?e=402;
error_page 403 /error.php?e=403;
error_page 404 /error.php?e=404;
error_page 500 501 502 /error.php?e=50x;

and so on.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, that's what I am currently doing. Just wanted to know if it could be simplified :( Because with that, a simple change will require lots of config changes, which I want to avoid :(
Looks unavoidable to me, alas. If you're looking at changing the name of the file readily though, you could try setting it as a variable with set $foo bar -- maybe something like set $errorpage error.php?e= would work best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.