Nginx 用作反向代理时,连接数不会超过 750

Nginx 用作反向代理时,连接数不会超过 750

我有一个移动应用程序,其中我们使用 Nginx 作为反向代理,将请求路由到 Nginx。应用服务器中的 Nginx 请求被传递给 Node.js 进行处理。当我们访问超过 750 个用户时,我们收到 504 网关超时错误。我们在 Nginx 日志中看到以下错误。

upstream timed out (110: Connection timed out) while connecting to upstream, client: LoadGenerator_IP, server: WebserverDNS, request: "GET /api/sample/profile HTTP/1.1", upstream: "https://app_server:443/api/sample/profile", host: "webserver_IP"

我尝试直接访问应用服务器 Nginx。我们可以访问超过 1000 个用户。但如果我们使用反向代理,就会收到该错误。

我尝试了很多 Linux 系统和 Nginx 设置,但都无法解决这个问题。

NGINX配置文件

 user  nginx;
 worker_processes  auto;
 worker_rlimit_nofile 100000;
 error_log  /var/log/nginx/error.log error;
 pid        /var/run/nginx.pid;
 events {
      worker_connections 4096;
      use epoll;
      multi_accept on;
 }
 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"'
                            'uct="$upstream_connect_time"'
                            'uht="$upstream_header_time"'
                            'urt="$upstream_response_time"'
                            'rt="$request_time "';
      access_log  /var/log/nginx/access.log  main;
      sendfile        on;
      #tcp_nopush     on;
      #tcp_nodelay on;
      # to boost I/O on HDD we can disable access logs
      access_log off;
      keepalive_timeout  120;
      keepalive_requests 10000;
      # allow the server to close connection on non responding client, this will free up memory
      reset_timedout_connection on;
      # request timed out -- default 60
      client_body_timeout 10;
      # if client stop responding, free up memory -- default 60
      send_timeout 2;
      #gzip on;
      # gzip_static on;
      #gzip_min_length 10240;
      #gzip_comp_level 1;
      #gzip_vary on;
      #gzip_disable msie6;
      #gzip_proxied expired no-cache no-store private auth;
      #gzip_types
           # text/html is always compressed by HttpGzipModule
      #    text/css
      #    text/javascript
      #    text/xml
      #    text/plain
      #    text/x-component
      #    application/javascript
      #    application/x-javascript
      #    application/json
      #    application/xml
      #    application/rss+xml
      #    application/atom+xml
      #    font/truetype
      #    font/opentype
      #    application/vnd.ms-fontobject
      #    image/svg+xml;
      include /etc/nginx/conf.d/Default.conf;
 }

默认配置文件

 upstream app_server {
    server app_server_ip:443;
 }
 server {
    listen       80;
    listen 443 ssl backlog=32768;
    server_name someIP;
    server_tokens off;
    location ~ {
      proxy_pass https://app_server_ip;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $host;
      #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_connect_timeout 75;
      proxy_read_timeout 300;
      proxy_send_timeout 300;
      proxy_http_version 1.1;
      proxy_set_header Connection "";
    }
    ssl_certificate /etc/ssl/certs/uatweb.crt;
    ssl_certificate_key /etc/ssl/certs/uatweb.key;
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers On;
    ssl_ciphers ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    location / {
      root   /usr/share/nginx/html;
      index  index.html index.htm;
    }
    #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   /usr/share/nginx/html;
    }   
 }
 server {
    listen       8114 ssl;
    server_name someServerName;
    ssl_certificate /etc/ssl/certs/uatweb.crt;
    ssl_certificate_key /etc/ssl/certs/uatweb.key;
    ssl_protocols TLSv1.1 TLSv1.2;
    location ~ {
      proxy_pass https://someIP;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
 }

如果配置文件需要进行任何更改,请告诉我。

答案1

这看起来是你的应用服务器的问题,而不是 nginx。我想说你遇到了问题proxy_connect_timeout- 但这个设置为 75 秒,看起来很多。你可以尝试增加这个值,但问题可能出在其他地方。

在测试应用后端本身时,能够“吸引超过 1000 名用户”意味着什么?您是如何测试的?这些并发用户是否请求相同的资源?您获得的响应时间是多少?

相关内容