[英]504 gateway timeout on hitting an endpoint
我目前正在訪問一個返回 JSON 響應的端點。 但有時當計算時間很大時,它會給出504 gateway timeout error 。 下面是我的代碼片段
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'
我還想知道有沒有辦法配置 nginx 設置以增加命中端點時的超時。 (我控制了服務器)
請提出解決方法。
如果你有Nginx
作為代理服務器,你可以在配置文件中增加timeout
。
server {
...
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
...
}
但不要忘記重啟Nginx
服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.