3

My server configuration looks like this: Nginx1 (proxycache) <---------> Nginx2 <-> PHP-FPM

When PHP-FPM fails because of the process is down ( errorconnect to unix:/run/php/php7.0-fpm.sock failed: No such file or directory while connecting to upstream) or because of pm.max_children has been reached Nginx2 returns a 404. I have looked if this behavior is set anywhere in my configuration but it looks it's the default.

If Nginx1 gets a 502 error code from Nginx2 will show the stale version of the page and that's why I want it to return a 502 code. I know I can configure Nginx to use the stale version when it gets a 404 from upstream but it there is no way to differentiate that from a normal 404 when a file gets deleted.

  • What is your complete nginx confuguration? – Tero Kilkanen May 29 '18 at 18:06
3

Usually this happens if you configure php to display errors:

 php_admin_value[display_errors] = On

nginx considers the error msg a valid page and changes the http status code.

Ref: https://stackoverflow.com/questions/11421240/why-does-display-errors-change-the-http-status-code

  • that looks correct, but it seems to me that it should be logged as a bug with PHP - displaying errors shouldn't interfere with the protocol, look what it does to nginx – Sum1sAdmin May 28 '18 at 9:33
  • 1
    I will review this but I'm referring to situations when php-fpm is not processing the request, not when there is an error in the PHP code (like the question you mention), so I don't think the PHP configuration matters. One of the tests I do is literally executing service php7.0-fpm stop. In that case Nginx2 returns a 404 ( ( errorconnect() to unix:/run/php/php7.0-fpm.sock failed (2: No such file or directory)) and I want it to return a 502. – brainsqueezer May 28 '18 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.