有没有办法让 EC2 实例中的请求存活时间超过 60 秒?
Is there a way to keep alive request longer than 60s in EC2 instance?
大家好,我一直在尝试在 amazon 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 / { }``` 块中。
我建议先整理您的配置;您在不了解它们的真正用途的情况下设置了一些值,然后包含另一个配置文件,然后设置更多,然后包含更多配置。
更改它以便您执行包含,然后然后覆盖您想要的值。
我已经对各种设置进行了注释,以便您了解它们的用途;这些经常被 cargo-cult 复制,希望它们起作用。唯一真正需要 86400s
(24 小时!)的是 proxy_read_timeout
:
我怀疑正在发生的事情是 /etc/nginx/conf.d/*.conf
中的一个 conf 文件具有 proxy_read_timeout
的 60s
(或 1m
)设置,即使您给出了这是一个更大的值,您再次调用 include
将覆盖您的设置。
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)
}
大家好,我一直在尝试在 amazon 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 / { }``` 块中。
我建议先整理您的配置;您在不了解它们的真正用途的情况下设置了一些值,然后包含另一个配置文件,然后设置更多,然后包含更多配置。
更改它以便您执行包含,然后然后覆盖您想要的值。
我已经对各种设置进行了注释,以便您了解它们的用途;这些经常被 cargo-cult 复制,希望它们起作用。唯一真正需要 86400s
(24 小时!)的是 proxy_read_timeout
:
我怀疑正在发生的事情是 /etc/nginx/conf.d/*.conf
中的一个 conf 文件具有 proxy_read_timeout
的 60s
(或 1m
)设置,即使您给出了这是一个更大的值,您再次调用 include
将覆盖您的设置。
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)
}