SoFunction
Updated on 2025-03-04

Causes and solutions for 504 errors (Gateway timeout) in Vue application

When a 504 proxy error is encountered in a Vue front-end application, this usually means that the request timed out before it reaches the server. 504 The error code indicates that the gateway timed out, that is, the proxy server did not receive a response from the upstream server within the specified time. This situation may be caused by a variety of reasons. Here are some common causes and solutions:

Common causes and solutions

Backend service response slow or not

  • Check backend services: Make sure the backend service is running and responding properly.
  • View log: Check the log of the backend service to see if there are any errors or exception information.
  • Performance optimization: If the backend service takes too long to process requests, consider optimizing the code or increasing the server resources.

Network issues

  • Check network connection: Ensure the network connection between the front-end and the back-end is stable.
  • Firewall or security group configuration: Check if there is a firewall or security group rule that blocks the request.

Proxy configuration issues

  • Check the proxy configuration: If you are using Nginx, Apache, or other reverse proxy server, make sure the configuration is correct.
  • Nginx sample configuration
http {
    proxy_read_timeout 120s;  # Increase timeout    proxy_send_timeout 120s;
    proxy_connect_timeout 120s;

    server {
        listen 80;
        server_name ;

        location /api/ {
            proxy_pass http://backend_server;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

The request load is too large

  • Optimization request: Check whether the requested data volume is too large and try to reduce the amount of data each time.
  • Page or batch request: If you need a lot of data, consider using paging or batch requests.

Front-end request timeout setting

  • Adjust request timeout time: If you are using Axios or other HTTP clients, you can adjust the requested timeout time.
  • Axios example
('/api/data', {
    timeout: 120000  // Set the timeout to 120 seconds})
.then(response => {
    ();
})
.catch(error => {
    ('Error:', error);
});

Insufficient server resources

  • Increase resources: Check the server's CPU, memory and disk usage, and increase resources if necessary.
  • Load balancing: If a single server cannot process all requests, consider using a load balancer to spread the requests.

Third-party service issues

  • Check third-party services: If the application depends on third-party services, ensure that these services are also operating normally.

Debugging steps

View the browser developer tools:

  • Open the browser's developer tools (usually press F12), view the request details under the Network tab, and confirm whether the request timed out.

Check server log:

  • View log files for front-end and back-end servers, looking for error messages or exceptions.

Test using Postman or cURL:

  • Use Postman or cURL tools to test API requests directly to confirm whether the problem lies in the front-end or back-end.

Summarize

The 504 proxy error encountered in Vue front-end applications is usually caused by the request timeout before reaching the server. The 504 error indicates that the gateway timeout is timed out, which may be caused by slow response of the back-end service, network problems, wrong proxy configuration, excessive request load, improper front-end request timeout setting, insufficient server resources or third-party service problems. Solutions include checking the back-end service, optimizing network connections, adjusting the proxy settings, optimizing the amount of request data, adjusting the request timeout setting, increasing server resources, etc. These methods can usually solve the 504 error. If the problem persists, further checking the system configuration and network environment.

This is the article about the reasons and solutions for the 504 error in Vue application. For more related contents of Vue front-end encountering 504 errors, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!