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

1

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

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

By exactly I specify 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.

    
asked by anonymous 05.02.2014 / 17:42

2 answers

2

You can do it in different ways

 error_page 502 /arquivo502.html

or forward the call to a pseudo location and handle 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 this case it can help prevent it from forwarding the errors ... or if you want to handle ... force them to be forwarded

fastcgi_intercept_errors off;
    
05.02.2014 / 18:23
0

If I understood correctly what it wants, it is to show the execution errors.

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

[raiz]php.ini
DISPLAY_ERRORS= ON

In my case I define more does not work so to treat the error I am forced to force PHP to display the warnings with

ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);
    
12.10.2014 / 19:54