我使用 5 個 nginx 伺服器作為我的來源站的反向代理。我的來源僅發送 HLS 內容,即 .ts、.aac、.vtt 和 .m3u8 檔案。
這在大多數情況下都工作得很好,但是當我有大約 8k - 12k 活動連接時,大約 150rq/s 我開始看到效能下降。
我提供的最大檔案約為 3M,即 2.5mbps。
我希望找到一種方法來允許更多的活動連接或至少 12k 連接而不降低效能。
user nginx;
worker_processes 8;
worker_priority -15;
worker_rlimit_nofile 1048576;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1048576;
multi_accept on;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main_ext '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$host" sn="$server_name" ' 'rt=$request_time ' 'ua="$upstream_addr" us="$upstream_status" ' 'ut="$upstream_response_time" ul="$upstream_response_length" ' 'cs=$upstream_cache_status' ;
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log main_ext;
access_log syslog:server=unix:/dev/log,tag=amplify,severity=info main_ext;
sendfile on;
#tcp_nopush on;
#tcp_nodelay on;
keepalive_timeout 120;
keepalive_requests 100000;
connection_pool_size 8192;
#gzip on;
open_file_cache max=400000 inactive=30s;
open_file_cache_errors off;
open_file_cache_min_uses 1;
open_file_cache_valid 60s;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
和
upstream backend {
ip_hash;
keepalive 100;
server server1;
server server2;
}
proxy_cache_path "/mnt/Delta/nginx_cache/nginx5/tmp/" levels=1:2 keys_zone=hls:10m inactive=2h use_temp_path=off;
proxy_cache hls;
proxy_cache_min_uses 1;
server {
listen 80;
#server_name localhost;
location = /healthz {
return 200;
access_log off;
}
location / {
root /mnt/Delta/nginx_cache;
try_files $request_uri @proxy_origin;
}
# location ~* \.(mpd)$ {
# rewrite /middle/([^/]+)/$1 break;
# proxy_cache off;
# expires -1;
# proxy_pass http://backend$1;
# }
location ~* \.(m3u8)$ {
rewrite /middle/([^/]+)/$1 break;
#proxy_cache off;
#expires -1;
proxy_cache_valid 200 302 5s;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
add_header X-Proxy-Cache $upstream_cache_status;
add_header Host Nginx5;
proxy_buffering on;
proxy_buffer_size 1024k;
proxy_buffers 5 1024k;
proxy_pass http://backend$1;
}
#location ~* \.(ts)$ {
# root /mnt/Delta/nginx_cache/tmp;
# try_files $request_uri @proxy_origin;
# proxy_pass http://backend$1;
#}
location @proxy_origin {
#resolver 10.196.160.160;
#proxy_buffering on;
#proxy_buffer_size 4096k;
#proxy_buffers 5 4096k;
proxy_pass http://backend$1;
proxy_cache_valid 404 3s;
proxy_cache_methods GET HEAD;
proxy_redirect off;
proxy_http_version 1.1;
proxy_read_timeout 10s;
proxy_send_timeout 10s;
proxy_connect_timeout 10s;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_cache_lock on;
#proxy_temp_path "/mnt/Delta/nginx_cache/nginx2/tmp";
#proxy_store "/mnt/Delta/nginx_cache/nginx2/tmp/$request_uri";
#proxy_store_access user:rw group:rw all:r;
#proxy_method GET;
proxy_set_header Host $host;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
add_header X-Proxy-Cache $upstream_cache_status;
add_header Host Nginx5;
}
}