504到达端点时网关超时

时间:2020-04-06 16:16:02

标签: python nginx http-status-code-404

我当前正在命中一个返回JSON响应的端点。但是有时,当计算时间较长时,它会给出 504网关超时错误。下面是我的代码段

Python代码

import json, requests
ans = requests.get(url).text
card_data = json.loads(ans)
print(card_data) # this is where response gets stored

暂停状态文本

'<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor="white">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>nginx/1.14.0 (Ubuntu)</center>\r\n</body>\r\n</html>\r\n'

enter image description here

我还想知道是否有一种方法可以配置nginx设置以增加在命中端点时的超时时间。 (我可以控制服务器)

请提出解决方法。

1 个答案:

答案 0 :(得分:0)

如果您将Nginx作为代理服务器,则可以在配置文件中增加timeout

server {
...
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
...
}

但是请不要忘记重启Nginx服务器。