What can I do to fix a 504 gateway timeout error?
Asked Answered
R

3

29

I have been using jquery to try and pull data from an API. However I am getting a 504 error. Even when I am using postman to test the data this happens. Can anyone suggest what I need to do to get around this?

Rozanna answered 7/5, 2017 at 14:1 Comment(0)
S
21

I recently experienced this issue on one of my app's that was making an ambitious call to it's Firebase Database - it was grabbing a very large record, which took over 60 seconds (the default timeout) to retrieve.

For those experiencing this error, that have access to their app / site's hosting environment, which is proxying through NGINX, this issue can be fixed by extending the timeout for API requests.

In your /etc/nginx/sites-available/default or /etc/nginx/nginx.conf add the following variables:

proxy_connect_timeout       240;
proxy_send_timeout          240;
proxy_read_timeout          240;
send_timeout                240;

Run sudo nginx -t to check the syntax, and then sudo service nginx restart.

This should effectively quadruple the time before NGINX will timeout your API requests (the default being 60 seconds, our new timeout being 240 seconds).

Hope this helps!

Staid answered 3/10, 2018 at 1:6 Comment(1)
This worked. I don't know why it works because previously it took more than 60 seconds and gave me the 504 error. But after including these configurations now it doesn't take at least 10 seconds to complete the task successfully. confused! anyways this works. thanksFulbert
S
9

There is nothing you can do.

You are sending a request to a server. This particular request fails, because the server sends a request to a proxy, and gets a timeout error. Your server reports this back to you as status 504.

The only way to fix it is to fix the proxy (make it respond in a timely manner), or to change the server to not rely on that proxy. Both are outside your area.

You cannot prevent such errors. What you can do is find out what user experience there should be when such a problem happens, and implement it. BTW. If you get 504 errors, then you should also expect timeout errors. Say you make a request to your server with 60 second timeout, and your server makes a request to the proxy with 60 second timeout. Because both timeouts are the same, sometimes your server will receive the proxy timeout and send it to you (status 504), but sometimes your request to the server will time out just before that, and you get a timeout error.

Seismology answered 7/5, 2017 at 14:20 Comment(1)
How do you "fix the proxy" with regards to this issue, please?Inflexion
A
-4

One way to fix this is, Changing proxy settings to "NO PROXY" in the browser

It works in Firefox browser, Others I don't know.

Follow the steps: 1. Go to preferences (top right corner 3 lines, search in drop down)

  1. Search for proxy (Ctrl+F)

  2. Go inside the settings

  3. select "NO PROXY" in the choice buttons, below "Configure Proxy Access to the Internet"

  4. refresh web page.

Arleanarlee answered 19/2, 2020 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.