有没有办法让 EC2 实例中的请求保持超过 60 秒?
Posted
技术标签:
【中文标题】有没有办法让 EC2 实例中的请求保持超过 60 秒?【英文标题】:Is there a way to keep alive request longer than 60s in EC2 instance? 【发布时间】:2021-12-06 05:45:44 【问题描述】:大家好,我一直在尝试在亚马逊 aws ec2 实例上执行我们的 django 应用程序。一切正常,除了超过 60 秒的请求。这些请求会自动获得504 Gateway Time-out
。我在安全组中为我的 EC2 实例配置了所有需要的端口。
我们正在使用 nginx,我的 nginx.conf 看起来像:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events
worker_connections 1024;
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;
keepalive_timeout 3600s;
client_max_body_size 500M;
client_body_timeout 86400s;
client_header_timeout 86400s;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
proxy_connect_timeout 86400s;
proxy_send_timeout 86400s;
proxy_read_timeout 86400s;
send_timeout 86400s;
#gzip on;
include /etc/nginx/conf.d/*.conf;
我尝试使用keepalive_timeout
,正如许多帖子所建议的那样,但它不起作用。也有很多帖子提到负载均衡器配置,但我什至没有使用负载均衡器,所以这应该与它无关。
如何管理我的实例以处理超过 60 秒的请求?
更新:
通过在 django 容器中搜索 server
块来解决(如 @jaygooby 建议的那样)。我修改了/etc/nginx/sites-enabled/mydjango
并将proxy_read_timeout 60m;
添加到我的````location / ``` 块中。
【问题讨论】:
更改后是否重启了nginx?你需要重启它 @ErmiyaEskandary 是的,我确实重启了 nginx 【参考方案1】:我建议先整理一下你的配置;您在设置一些值时不了解它们的真正用途,然后包含另一个配置文件,然后设置更多,然后包含更多配置。
更改它以便您执行包含并然后覆盖您想要的值。
我已对各种设置进行了注释,以便您了解它们的用途;这些经常被货物崇拜复制,希望它们能奏效。唯一真正需要像86400s
(24 小时!)这样的东西是proxy_read_timeout
:
我怀疑发生的事情是/etc/nginx/conf.d/*.conf
中的一个 conf 文件有一个60s
(或1m
)设置为proxy_read_timeout
,即使你给了这个更大的值,你也调用了@ 987654327@ 再次覆盖您的设置。
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events
worker_connections 1024;
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;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
client_max_body_size 500M; # Don't allow uploads larger than 500MB
client_body_timeout 86400s; # Defines a timeout for reading client
# request body. The timeout is set only
# for a period between two successive read
# operations, not for the transmission of
# the whole request body
client_header_timeout 86400s; # Defines a timeout for reading client
# request header; ie. the client's initial
# HEAD, GET or POST
proxy_connect_timeout 86400s; # Time to *open* a connection to the proxy
# before we give up
proxy_send_timeout 86400s; # Timeout for transmitting a request *to*
# the proxied server
proxy_read_timeout 86400s; # Timeout for reading a response from the
# proxied server - did it send back
# anything before this has expired
send_timeout 86400s; # Timeout for sending a response to the
# requesting client - note this isn't
# proxy_send_timeout, but the time between
# two successive write operations to the
# requesting client (ie. browser)
【讨论】:
我检查了 /etc/nginx/conf.d/ 它是空的,所以所有的 nginx 设置都来自基础 nginx.conf。我也尝试了你给我的设置,但我无法摆脱这个错误 504 Gateway Time-out @Yusepp 在上面的配置中没有server
块,在您发布的配置中也没有,所以一定有一个。你能编辑你的问题,所以你也包括在内(我猜它可能是/etc/nginx/sites-enabled/
中的default
文件?
我的/etc/nginx/
(在docker里面)看起来像这样conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
我找不到sites-enabled
某处必须有一个server
块-您问题中的nginx.conf
是整个文件吗?
现在工作了!!!谢谢以上是关于有没有办法让 EC2 实例中的请求保持超过 60 秒?的主要内容,如果未能解决你的问题,请参考以下文章