Reputation: 477
I have a golang web server running on AWS elastic beanstalk in this machine: Go 1 running on 64bit Amazon Linux 2; The error occurs when I make a request to the server and it executes several processes, so it takes around 90 seconds to complete the entire process, so after 60 seconds the AWS beanstalk server ends the client connection and returns the following error, although the process ends completely after 90 seconds. It sends the following error:
<html>
<head>
<title>504 Gateway Time-out</title>
</head>
<body>
<center>
<h1>504 Gateway Time-out</h1>
</center>
</body>
</html>
Source application files:
.
├── application.go
├── cron.yaml
└── public
└── index.html
When I tested it on my local machine It works well and It take 90 seconds, only when It runs on Beanstalk has this issue. How can I fix it ??
Upvotes: 2
Views: 793
Reputation: 2217
504 Gateway Timeout
indicates that the nginx proxy is waiting too long for a response from the upstream app. If this happens for an endpoint that usually returns after a few seconds, it is very likely that the nginx proxy is trying to reach a port that your app is not listening on (or that the app has crashed).
By default, Elastic Beanstalk configures the nginx proxy to forward requests to your application on port 5000. You can override the default port by setting the PORT
environment property to the port on which your main application listens. More info: AWS Reverse Proxy Docs
Make sure that your application code listens on the right port.
http.ListenAndServe(":5000", nil);
Another reason for this could be a crash in the app code. Check the last 100 log lines in Elastic Beanstalk. You can also retrieve the logs by SSH'ing into your server and running cat /var/log/eb-engine.log
.
On a separate note, it looks like you're trying to statically host /public/index.html
. You can do this in 2 separate ways.
http.Handle("/", http.FileServer(http.Dir("./static")))
http.ListenAndServe(":3000", nil)
By extending your nginx config you can use the proxy server to statically host files and redirect routes before they hit your server application.
~/workspace/my-app/
|-- .platform
| `-- nginx
| `-- conf.d
| `-- myconf.conf
Upvotes: 1