nginx - Nginx 无法处理大量请求
问题描述
我有一个关于 nginx 在 Artifactory 服务器前面的场景。最近,在尝试在 for 循环中同时拉取大量 docker 图像时(第一次测试使用 200 个图像,第二次测试使用 120 个图像),访问 Artifactory 被阻止,因为 nginx 正忙于处理所有请求和用户将无法访问它。
我的 nginx 服务器运行 4 个 cpu 核心和 8192 个内存。
我试图通过添加以下内容来改进服务器中文件的处理:
sendfile on;
sendfile_max_chunk 512k;
tcp_nopush on;
这使它变得更好一些(当然,由于块大小,拉取 1gb+ 的图像需要更多时间)——仍然,访问 UI 会导致很多超时。
每当有更大的负载通过它时,我还能做些什么来提高 nginx 性能吗?
我认为我的最后一个选择是增加机器的大小(更多的 cpu)以及 nginx 上的进程数(8 到 16)。
完整的 nginx.conf 文件如下:
user www-data;
worker_processes 8;
pid /var/run/nginx.pid;
events {
worker_connections 19000;
}
http {
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
include /etc/nginx/mime.types;
default_type application/octet-stream;
gzip on;
gzip_disable "msie6";
sendfile on;
sendfile_max_chunk 512k;
tcp_nopush on;
set_real_ip_from 138.190.190.168;
real_ip_header X-Forwarded-For;
log_format custome '$remote_addr - $realip_remote_addr - $remote_user [$time_local] $request_time'
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
server {
listen 80 default;
listen [::]:80 default;
server_name _;
return 301 https://$server_name$request_uri;
}
###########################################################
## this configuration was generated by JFrog Artifactory ##
###########################################################
## add ssl entries when https has been set in config
ssl_certificate /etc/ssl/certs/{{ hostname }}.cer;
ssl_certificate_key /etc/ssl/private/{{ hostname }}.key;
ssl_session_cache shared:SSL:1m;
ssl_prefer_server_ciphers on;
## server configuration
server {
listen 443 ssl;
server_name ~(?<repo>.+)\.{{ hostname }} {{ hostname }} _;
if ($http_x_forwarded_proto = '') {
set $http_x_forwarded_proto $scheme;
}
## Application specific logs
access_log /var/log/nginx/{{ hostname }}-access.log custome;
error_log /var/log/nginx/{{ hostname }}-error.log warn;
rewrite ^/$ /webapp/ redirect;
rewrite ^//?(/webapp)?$ /webapp/ redirect;
rewrite ^/(v1|v2)/(.*) /api/docker/$repo/$1/$2;
chunked_transfer_encoding on;
client_max_body_size 0;
location / {
proxy_read_timeout 900;
proxy_max_temp_file_size 10240m;
proxy_pass_header Server;
proxy_cookie_path ~*^/.* /;
proxy_pass http://{{ appserver }}:8081/artifactory/;
proxy_set_header X-Artifactory-Override-Base-Url $http_x_forwarded_proto://$host:$server_port;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
感谢您的提示。
干杯,里卡多
解决方案
推荐阅读
- vega-lite - vega-lite 中的动态尺度域
- android - 如果数据库中没有任何内容,如何显示“无数据”吐司
- javascript - 查看 p5.js 钢琴乐器的代码
- sql - 是否可以在 SQL 中按语句分区进行多次计算?
- angular - Angular/Ngx 翻译:动态显示从服务器获取的 currentLang
- r - dplyr group_by 并用组的函数替换所有列
- fortran - 每次使用包含模块时都会评估 Fortran 命名常量吗?
- html - 沿 SVG 路径为项目设置动画
- flutter - Flutter 监听 Stateless Widget 上的生命周期事件?
- json - 如何在 Jackson (2.12.0) 和 Quarkus (1.11.1) 中使用 Kotlin (1.4.21) 数据类的默认值