nginx每秒请求都会变慢

时间:2014-10-27 14:22:39

标签: node.js nginx

我目前正在为我的网站创建一个api,使用nodejs和nginx,我为每个nodejs app设置了反向代理我将运行(api,mainsite,其他东西......)

但是,当我尝试使用api时,它会在每次请求时使用很长时间,有时会超时...

NGINX.CONF

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user              nginx;
worker_processes  24;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  19000;
    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"';

    access_log  /var/log/nginx/access.log  main;

    #SSL performance tuning
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         ECDHE-RSA-AES128-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
    ssl_prefer_server_ciphers   on;
    ssl_session_cache       shared:SSL:10m;
    ssl_session_timeout     10m;

    ssl_stapling        on;
    ssl_stapling_verify     on;
    resolver            8.8.8.8 8.8.4.4 valid=300s;
    resolver_timeout        10s;
    add_header          Strict-Transport-Security "max-age=31536000";

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay             on;
    keepalive_timeout       10;

    gzip            on;
    gzip_disable        "msie6";
    gzip_min_length     1000;
    gzip_proxied        expired no-cache no-store private auth;
    gzip_types          text/plain application/xml application/javascript text/css application/x-javascript;  

    #for mulyiple domains, www.codewolf.red, codewolf.red
    server_names_hash_bucket_size 64;

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;

}

error.log中

2014/10/27 14:26:46 [error] 6968#8992: *15 WSARecv() failed (10054: FormatMessage() error:(317)) while reading response header from upstream, client: ::1, server: localhost, request: "GET /api/ffd/users HTTP/1.1", upstream: "http://127.0.0.1:3000/ffd/users", host: "localhost"

2014/10/27 14:27:46 [error] 6968#8992: *15 upstream timed out (10060: FormatMessage() error:(317)) while connecting to upstream, client: ::1, server: localhost, request: "GET /api/ffd/users HTTP/1.1", upstream: "http://[::1]:3000/ffd/users", host: "localhost"

2014/10/27 14:39:31 [error] 6968#8992: *20 upstream timed out (10060: FormatMessage() error:(317)) while connecting to upstream, client: ::1, server: localhost, request: "GET /api/ffd/users HTTP/1.1", upstream: "http://[::1]:3000/ffd/users", host: "localhost"
2014/10/27 14:40:09 [notice] 5300#1352: signal process started

任何想法都错了吗? 它已经有一段时间了,它杀了我:(

请帮忙,这会浪费我开发应用的时间:/

2 个答案:

答案 0 :(得分:4)

添加此内容是因为这对我有用

https://forum.nginx.org/read.php?15,239760,239760似乎表明您可以proxy_pass到127.0.0.1而不是localhost,并且请求可以顺利通过

  

macbresch

     

一岁,但我想指出,该问题可以解决。就像Cruz Fernandez所写的那样,您可以在proxy_pass指令上设置127.0.0.1而不是localhost。这样可以防止每秒钟请求延迟60秒。我正在使用Windows 8.1和nginx 1.9.5。

     

Cruz Fernandez写:

     

您可以使用127.0.0.1(而不是proxy_pass指令上的localhost)

location /nodejsServer/ {
    proxy_pass http://127.0.0.1:3000/;
}

答案 1 :(得分:2)

我能够通过使用上游语句来解决这个问题。

例如。 :

TextField field = new TextField(writer, new Rectangle(x, y - h, x + w, y), name);
field.BackgroundColor = new BaseColor(bgcolor[0], bgcolor[1], bgcolor[2]);
field.BorderColor = new BaseColor(
    bordercolor[0], bordercolor[1], bordercolor[2]);
field.BorderWidth = border;
field.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
field.Text = text;
writer.AddAnnotation(field.GetTextField());

参考:http://nginx.org/en/docs/http/ngx_http_upstream_module.html