After the connection between Nginx and the back-end server timed out, how to configure it if you want Nginx to return json data to the client?

suppose the requirement is as follows:
Nginx listens on port 80, the domain name of the backend server assumes http://hello.com,
Nginx accepts requests from the client as a proxy, and then Nginx forwards the request to http://hello.com. If the connection between Nginx and the back-end server times out, you have to return the data in json format to the client. The data is assumed to be like this:

{
    "code": -1
    "message":"failed to connect remote error"
} 

and the status code you want the client to receive is 500.
I would like to ask the seniors to achieve this function, how to configure Nginx?


proxy_intercept_errors on;
error_page 504 = @500;
location @500 {
    default_type application/json;
    return 500 '{"code": -1,"message":"failed to connect remote error"}';
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c204a1-32a24.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c204a1-32a24.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?