How to make Nginx display error messages on screen in the same way as Apache does instead of '502 bad gateway'

Asked

Viewed 960 times

1

Nginx and Apache present errors differently when there is a problem running a PHP script. Apache, when configured to display on screen, displays exactly the error, with file and line where it occurred, but Nginx usually displays only something like 502 bad gateway.

Most solutions, even in stackoverflow.com at most help you set up NGinx and the PHP-FPM to direct errors to a text file, but I personally could not get Nginx to display the errors exactly like the Apache would. I understand that in production it is not ideal to display screen errors to the user, but a constant problem when using Nginx instead of Apache for a developer to test their application is that most have difficulty debugging just by looking at log files.

For exactly specifies that it is all possible errors that theoretically Nginx could display. If a php-fpm worker is not active or has serious problems it would be acceptable to still have the same errors

  • Some user with enough score could create the tag php-fpm please? Not yet in en SO.

2 answers

2

can do several ways

 error_page 502 /arquivo502.html

or forward the call to a pseudo Location and handle by the application

error_page 502 @teste
location @teste {
  <faça o que quiser aqui>
}

there may be an error in php-fpm because it is a proxy... in which case it can help prevent it from forwarding errors... or if you want to handle... force them to be forwarded

fastcgi_intercept_errors off;
  • error_page 502 /arquivo502.html would only redirect to a different error, not display the error. And what <faça o que quiser aqui> in fact it should be to display the real mistakes? It was not clear.

  • is that in the specific case of 502 php-fpm did not respond in time or did not answer the header correctly.. then there is no way to forward in an elegant way the error that came from php... see the error log of Nginx... it makes the raw log of cgi there..

  • maybe just to keep in development... you could put Location forwarding to a php that deprivte on the screen the last lines of Nginx errolog... is not beautiful... but will simplify the process...

0

If I understand well what you want is to show the execution errors.

Usually with apache you just enable DISPLAY_ERRORS in the php.ini as follows.

[raiz]php.ini
DISPLAY_ERRORS= ON

In my case I define no longer work so to treat the error I am obliged to force PHP to display the warnings with

ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.