T
T
Tutucu2021-01-09 17:14:58
PHP
Tutucu, 2021-01-09 17:14:58

How to display JSON with response code 200 in NGINX on time-out?

Hello! There is a bunch of NGINX - php-fpm. I need that when the script hangs for more than 2 seconds, json is output with a response code of 200. I did the Json output, but I can’t change the code :( it always shows 504. How can this be done?
nginx config:

#Errors
error_page 504 /errors_json/index.php?504;
location = /errors_json/index.php {
root "/var/www/site/releases/public";
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
internal;
    }

index.php:
header( 'HTTP/1.1 200 OK' );
header('Content-Type: application/json');
$data = [
  'text' => 'Слишком долго думаю, повторите'
];

echo json_encode($data);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-01-09
@Tutucu

https://nginx.org/en/docs/http/ngx_http_core_modul...
Do you want to change the response code or something? error_pagedoes exactly what is described - gives a certain url on error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question