Answer the question
In order to leave comments, you need to log in
Requests to Node through Nginx hang
Good day to all.
It became interesting to play around with the combination of Node.JS + Nginx. Wrote a test site, raised nginx, but happiness did not come.
Nginx works just as a proxy, but there were problems with css (although sometimes there is a delay in loading the page itself, and then everything works fine). The request stupidly waits a minute. If you ask the site directly, everything works fine. Only through nginx - problems.
Node renders css as static content.
Answer the question
In order to leave comments, you need to log in
Isn't it easier to give statics directly through nginx? What is the point of pulling a node because of pictures and styles?
In a bunch of Nginx + node, with the correct configuration, there are no problems. Both static and dynamic.
However, if you describe how static content is served through a node, and a piece of the nginx config, then it is easier to give advice.
For example, static on a node is given by a dozen different modules, which one you use is not known.
Judging by the beautiful minute, the return occurs by timeout. The problem can be node code (which is most likely), or protocol (for example, after a minute of waiting for the thread to close, it closes automatically).
And where did you get such an example app.use(express.static(config.root + '/static'))
everywhere usually like this app.use(express.static(path.join(__dirname, 'static')))
Show app.js, it will be faster.
I have the same.
When you access the node directly through localhost:3000 , the page is returned instantly, and when you go through nginx localhost , every second request freezes.
There was the same problem on nginix 1.7.5 under Windows, in ubuntu on the default config everything was fine.
Solved by moving the url to the upstream directive
upstream psh_backend {
server 127.0.0.1:4020;
keepalive 64;
}
server {
listen 4010;
keepalive_timeout 10;
/ ****/
location /api {
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://psh_backend;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question