Nodejs response slow resolution after Nginx

Source: Internet
Author: User

Recently used Nodejs to build a server, and then use Nginx to do a reverse proxy, project development needs, no way. But found that after the agent found that the Web request is slow, and can not tolerate more than a minute.

At first, the suspicion is in the nodejs side of the problem, the result in Nodejs side of the judgment (by writing test code), but found that after a minute request to nodejs this side, then can only first eliminate nodejs this aspect of the problem.

So to rule out nginx problem, my environment is windows7 (x64) nginx (1.62) Nodejs (4.23), configured as follows

server {    listen;    server_name mysite.com;    Location/{        Proxy_set_header    x-real-ip           $remote _addr;        Proxy_set_header    x-forwarded-for     $proxy _add_x_forwarded_for;        Proxy_set_header    Host                $http _host;        Proxy_set_header    x-nginx-proxy       true;        Proxy_set_header    Connection          "";        Proxy_http_version  1.1;        Proxy_pass          http://localhost:3333;    }}

This is a more common configuration, can not find out the problem, then only to find the error log, suddenly found that the error log error.log inside there is such a code

2015/12/25 16:30:43 [ERROR] 7652#7008: * Upstream timed out (10060:a connection attempt failed because the Connect Ed party didn't properly respond after a period of time, or established connection failed because connected host had fail Ed to respond) and connecting to upstream, client:127.0.0.1, server

Did not pay attention to the error log before, the crime ah, then since the discovery of this error, find the method is much simpler.

Like Nodejs there is no response to nginx in a timely manner, then you can add these configuration to solve (in seconds)

Proxy_connect_timeout 1; Proxy_send_timeout 30; Proxy_read_timeout 60;

The three settings are defined as:

Proxy_connect_timeout
Timeout for backend server connection _ initiate handshake wait response time-out

Proxy_read_timeout
After the connection succeeds _ waits for the backend server response time _ actually already enters the back-end queue waits for processing (also can say is the back-end server processing request time)

Proxy_send_timeout
back-end server data return time _ is within the specified time, the backend server must pass all the data

After the addition, it is resolved, the complete is:

server {    listen;    server_name mysite.com;    Location/{        Proxy_set_header    x-real-ip           $remote _addr;        Proxy_set_header    x-forwarded-for     $proxy _add_x_forwarded_for;        Proxy_set_header    Host                $http _host;        Proxy_set_header    x-nginx-proxy       true;        Proxy_set_header    Connection          "";        Proxy_http_version  1.1;        Proxy_connect_timeout 1;         Proxy_send_timeout;         Proxy_read_timeout;        Proxy_pass          http://localhost:3333;    }}





Nodejs response slow resolution after Nginx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.