2014-10-27 138 views
1

我目前正在为我的网站创建一个API,使用nodejs和nginx,我已经为每个nodejs应用程序设置了反向代理我将运行(API,主要,其他的东西..) 。nginx缓慢的每一个第二个请求

然而,当我尝试我的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 

任何想法最新怎么了? 它已经这样了一段时间,并且其杀死我:(

请帮帮忙,它毁了我的开发应用时间:/

+1

你试过绕过nginx的,并直接连接到你的应用程序看起来像吴? INX无法连接到上游,我猜是你的应用程序。 – Martin 2014-10-27 15:50:23

+1

是的,我有。我通过设置一个上游变量并使用它来代替http:// localhost:2345 /尝试新的东西。现在一切正常! :) 我会写一个正确的答案,我会解释我如何解决它! – andersfylling 2014-10-27 20:14:37

回答

2

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

如:

upstream nodejs_server { 
    server 192.168.0.67:8080; #ip to nodejs server 
} 

#server config 
server { 
    location /nodejsServer/ { #http://localhost/nodejsServer/ 
     proxy_pass http://nodejs_server; 
    } 
} 

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

+0

这个问题可能是由于使用loopback接口(localhost)分别作为目标服务器和nginx的绑定目标,使用真实本地地址解决了我的问题。 – ShadowCode 2017-09-05 09:19:28