简体   繁体   中英

504 gateway timeout on hitting an endpoint

I am currently hitting an endpoint which returns a JSON response. But sometimes when the computation time is large, its giving an 504 gateway timeout error . below is my code snippet

Python Code

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

Respone status text

'<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'

在此处输入图像描述

I am also wondering is there a way to configure nginx settings to increase the timeout when endpoint is hit. (I have control of the server)

Please suggest a workaround.

If you have Nginx as a proxy server, you can increase the timeout in the config file.

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

But don't forget to restart the Nginx server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM