我想为超时或内部服务器错误设置json响应。
server {
server_name 192.168.1.16;
location / {
proxy_pass http://localhost:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 5s;
proxy_connect_timeout 5s;
proxy_send_timeout 6s;
send_timeout 5s;
}
location /static {
alias /home/oem/PycharmProjects/indiawyn-backend/static;
}
location ^~ /json_files {
root /home/www/;
}
}
我不知道在哪里配置。 请为此共享任何文档或答案。
答案 0 :(得分:0)
例如:
server {
...
error_page 500 /json_files/500.json;
error_page 504 /json_files/504.json;
...
}
在/home/www/json_files/500.json
和/home/www/json_files/504.json
文件中放置类似
{
"code": 500,
"error": "internal_server_error",
"error_description": "Internal server error"
}
,
{
"code": 504,
"error": "gateway_timeout",
"error_description": "Gateway timeout"
}
如果您的mime类型设置正确,nginx将自动添加Content-Type: application/json
标头。