I am using AWS Elastic Beanstalk for hosting Express/Node.js API server.
It's working well with just normal APIs but I am getting this 504 Timeout error with only one API which may take time for more than 20 mins at max.
So, I thought I needed to increase max request time of Nginx and Node.js server and I did it by configuring AWS EB .extensions and .platform variables.
Here is what I did.
.platform/nginx/conf.d/timeout.conf
client_header_timeout 3000s;
client_body_timeout 3000s;
send_timeout 3000s;
proxy_connect_timeout 3000s;
proxy_read_timeout 3000s;
proxy_send_timeout 3000s;
.ebextensions/network.config
option_settings:
- namespace: aws:elasticbeanstalk:command
option_name: Timeout
value: 3000
But I am still getting this error and I can't understand why this is happening.
Plus Note: Elastic Beanstalk server is covered by CloudFront and AWS Route 53 for giving it public domain address and HTTPS connection.
If somebody knows how to fix this, it will be appreciated a lot.
In case you are using a "Load balanced" environment type, check the "Connection idle timeout" setting of the Load Balancer.
To validate if your env uses a ELB go to "Elastic Beanstalk" -> "<your_environment> -> "Configuration" section and check if the "Load balancer" category is present. Here you can find also the type of ELB you are using. Then change the Connection idle timeout setting in the EC2 console to a proper value.
Related
I am Deploying a web application When executing the app url its showing this error. In logs, displaying this error, "Waiting for response to warmup request for container". Please help me with this.
Building a Python Based App. Tried using Docker Container in Azure Portal.
Try to increase the timeout on your webserver (e.g. nginx) or/and at python level, to allow your page to execute for longer.
You will receive a 504 error when the webserver waits too long for a page to be generated. The webserver closes the http request because it has reached a timeout.
Here some Nginx configurations to increase the timeout :
server {
server_name _;
root /var/www/html/public/;
###
# increase timeouts to avoid 504 gateway timeouts, digits are seconds
# for big files uploads
###
client_max_body_size 0;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
fastcgi_send_timeout 3600;
fastcgi_read_timeout 3600;
# ... your config
}
I'm not a Python developer but you may find some timeout configurations at Python level too (because there's a config in PHP to define the max_execution_time).
I have a node js application in Elastic Bean stalk.We are considering using socket io for a feature .
I read in some places that socket io support has to be manually enabled in AWS elasticbeanstalk. Specifically when it uses the default NGINX proxy.
I read By default an elastic beanstalk instance has an nginx proxy in front of it that is not configured to allow webSockets.
Is this correct information? If so , how to enable socket io support in AWS EB?
This is correct information. You'll need to do some additional configuration for your Elastic Beanstalk deployment to get WebSockets(Socket.io or otherwise) to work.
Once you create your Elastic Beanstalk Environment, you'll need to configure your load balancer to accept TCP connections, and add a configuration file to your node project's root directory:
Configure Load Balancer:
Head over to your EC2 console and select the Load Balancers tab
Select the load balancer that belongs to your ELB environment from
the list
Select the Listeners tab
Change the default entries' Instance Protocol to TCP
Add the Configuration File:
In the root directory of your node project, create a folder called
.ebextensions
Create a file called enable-websockets.config in your new .ebextensions folder with the following contents:
container_commands:
enable_websockets:
command: |
sed -i '/\s*proxy_set_header\s*Connection/c \
proxy_set_header Upgrade $http_upgrade;\
proxy_set_header Connection "upgrade";\
proxy_pass_request_headers on;\
' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
This file tells the NGINX reverse proxy how to handle the HTTP 101 upgrade status code that WebSockets need to communicate with your application server.
I try to implement Facebook authentification on my web application but I'm getting a 502 Bad Gateway error when my nodejs server try to send a response throw facebook/auth/callback request.
Here my request logs :
My nodejs server is deployed on elastic beanstalk and uses nginx proxy.
I read this error can occurs when response's is too big. So I tried to edit this size using the following code :
01buffer_proxy.con :
files:
"/etc/nginx/conf.d/app_proxy_buffer.conf" :
mode: "000644"
content: |
server {
location / {
proxy_buffering on;
proxy_buffer_size 16k;
proxy_buffers 32 16k;
client_body_buffer_size 128k;
proxy_busy_buffers_size 64k;
container_commands:
01_reload_nginx:
command: "service nginx reload"
}
But I still get the error.
Do you think it's a response's size problem ? If yes, how edit proxy buffer size on elastic beanstalk.
Thanks.
I am creating a test web app and have deployed it to AWS Ubuntu server using nginx..
I am getting a 502 Bad Gateway error when it tries to reach my API..
I am new to this and have started node.js and all seems to working fine except when I want to perform an API call to mongodb to read or write information. it is working fine locally so I am at a loss....
GET http://ec2-54-72-145-112.eu-west-1.compute.amazonaws.com/api/rest/golf 502 (Bad Gateway)
this is nginx server config
location /xxxxxxxxxxxxxxx{
alias /home/ubuntu/xxxxxxxxxxxxxx/site/public;
}
location /api/ {
proxy_pass http://127.0.x.1:8180/api/;
}
..
I know I may not be giving enough info but hopefully someone has an idea..
Thanks!
The nginx error message HTTP 502 indicates the nginx is working fine but cannot reach your specified proxy. So I'd suggest you to check whether the port and binding IP are correct.
You can check which ports are bound by which application using this command on your Ubuntu machine:
netstat -tulpen
You should see a line with the column "Local Address" and in your case the value 127.0.x.1:8180. If it's not there try to figure out which port is bound by your node application and reconfigure the nginx to use that port.
I deploy a nodejs application on the aws beanstalk servers and want to use socket.io feature based on WebSocket protocol. I know there's a discussion here to directly connect to nodejs servers instead of using nginx as an proxy server. But if I still want to have the nginx as proxy server because of extra features provide by nginx, such as static files, ...etc.
I find it's already support WebSocket proxying on nginx 1.3.13 and I found it seems aws elastic-beanstalk still use the 1.2.x nginx.
So I am wondering if there's any way to upgrade nginx version under beanstalk and how to enable WebSocket proxying to nodejs server.
Thanks
We use elastic beanstalk with multiple docker containers(allows you custom nginx version) with following
1.Nginx config
location /ws/
{
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://unix:/<<socket>>;
}
Enable TCP mode load balancing in elastic load balancer if you are using one.
You would need additional module enabled, which can be done during nginx compilation.
To do that you would need to add below line to your configuration script.
--add-module=/root/nginx_patched/nginx_tcp_proxy_module
It is required if you would like to get sockets enabled, for example for node.js socket.io. Full tutorial can be found here.
Sorry for the link but it is quite broad topic. You might need step by step guide if you starting from the scratch.
Hope it helps.