I am running a django app with nginx as webserver on an EC2 instance. The website gets a decent amount of API calls per minute depending on how many testpipelines I run. My problem is that the website times out sporadically. I can't reach it in the browswer and all my tests fail of course. Also I can't login to my instance anymore but have to wait until it is back up.... SHouldn't I at least be able ssh into it even though the website times out??
Now I am wondering: Is that rather an nginx configuration error or could it be that my EC2 does not have enough memory? I am deploying to an t2 micro instance on EC2 which has 1 vCPU and also only 1GB of memory. Let's say I get 20-30 API calls, all trying to download files between 10 and 50 MB. Do I need a bigger instance or should it be no problem to handle for the EC2?
Or could it be my nginx configuration? Right now I use this (I am not at all an nginx expert, please tell me if there are stupid configs set):
main config
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
send_timeout 90;
keepalive_timeout 90;
fastcgi_read_timeout 120;
proxy_read_timeout 120;
fastcgi_buffers 8 128k;
fastcgi_buffer_size 128k;
client_body_timeout 120;
client_body_buffer_size 128K;
client_header_buffer_size 1k;
large_client_header_buffers 4 8k;
client_header_timeout 120;
client_max_body_size 5G;
types_hash_max_size 2048;
server_tokens off;
gzip on;
gzip_static on;
gzip_min_length 512;
include /etc/nginx/conf.d/*.conf;
}
And server config
server {
listen 443 ssl;
server_name mywebsite.de;
proxy_max_temp_file_size 0;
proxy_buffering off;
charset utf-8;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/mywebsite.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.de/privkey.pem;
set $my_host $http_host;
if ($http_host = "mywebsite.de") {
set $my_host "mywebsite.de";
}
location / {
proxy_pass http://django:5000;
proxy_set_header Host $my_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 3600;
}
}
server {
listen 80 ;
server_name mywebsite.de;
return 301 https://mywebsite.de$request_uri;
}
server {
listen 80 ;
server_name www.mywebsite.de;
return 301 https://mywebsite.de$request_uri;
}
server {
listen 443 ;
server_name www.mywebsite.de;
return 301 https://mywebsite.de$request_uri;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/mywebsite.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.de/privkey.pem;
}
It could also be something else, but what else could crash my machine? Maybe Redis? I am not sure. I am looking for possible reasons this could happen and for possible solutions to have this as stable as possible.
Very grateful to the community for any help! Thanks in advance!
0 Answers