Nginx用作反向代理时,扩展规模不超过750个连接

时间:2019-05-15 08:19:38

标签: nginx performance-testing nginx-reverse-proxy

我有一个移动应用程序,其中我们使用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.CONF

 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;
 }

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;
    }
 }

请告诉我配置文件是否需要任何更改。

0 个答案:

没有答案