我在使用 NGINX 时遇到了问题。我将为多个(约 4000 人)用户提供文件,他们可能会同时下载多个文件。我已设置 nignx 并尝试下载一个测试文件(centos dvd 1 4GB),一旦我尝试同时多次下载同一个文件,它只允许我先下载一个,然后其他文件会等待我完成第一个下载。我怎样才能在不等待任何时间的情况下提供它。
NGINX.conf:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_rlimit_nofile 200000;
events {
worker_connections 10000;
multi_accept on;
use epoll;
}
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_requests 1000;
open_file_cache max=1000;
# Added on 26.07.2013 to make files fly!
tcp_nopush on;
client_max_body_size 5G;
client_body_timeout 120;
client_header_timeout 120;
client_body_buffer_size 128K;
client_header_buffer_size 1k;
large_client_header_buffers 4 8k;
send_timeout 60;
reset_timedout_connection on;
types_hash_max_size 2048;
server_tokens off;
gzip on;
gzip_static on;
gzip_min_length 512;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
虚拟服务器配置:
server {
listen 80;
server_name *.*.*.*;
root /usr/share/nginx/html;
error_log /var/log/nginx/deadz/error.log;
access_log /var/log/nginx/deadz/access.log;
index index.html index.htm index.php;
}
我如何才能优化它以便通过一个连接多次提供同一个文件。
如果您需要更多信息,请询问我。
答案1
服务器配置:
server {
listen 80;
server_name *.*.*.*;
root /usr/share/nginx/html;
error_log /var/log/nginx/deadz/error.log;
access_log /var/log/nginx/deadz/access.log;
index index.html index.htm index.php;
server_tokens off;
client_max_body_size 700m;
connection_pool_size 256;
client_body_buffer_size 1024k;
client_header_buffer_size 8k;
limit_rate 125k;
limit_req zone=one burst=5;
}
NGINX 配置:
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_rlimit_nofile 20240;
events {
worker_connections 4000;
multi_accept on;
use epoll;
}
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 off;
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
client_header_timeout 10m;
client_body_timeout 10m;
send_timeout 10m;
client_max_body_size 700m;
connection_pool_size 256;
client_body_buffer_size 1024k;
client_header_buffer_size 8k;
keepalive_timeout 30;
keepalive_requests 100000;
reset_timedout_connection on;
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
gzip on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
include /etc/nginx/conf.d/*.conf;
}
这解决了我的问题:)现在我需要设置 HAProxy 来平衡下载。