I have an RESTful API relying on nodejs and restify. It is being served on port 8989.
I have nginx listening to port 444 and I have a proxy pass like this one
location /v1/
{
proxy_pass http://localhost:8989;
}
Any call to something like
http://localhost:444/v1/hello
works fine, but only the first time. The second time it responds exactly 60 seconds later. If you cancel the request and try it again, then it works again, but the next time will be the same. So, after each successful call there is one that is delayed 60 seconds.
It only happens when the services are running on nodejs. I have tried changing the API framework to express and Percolator js and there is the same issue. However, when I try with a C# NancyFx API this issue doesn't happen.
Also, if you try to access the services directly, that is something like
http://localhost:8989/v1/hello
It always looks just fine.
After looking at the headers that were being sent to the retify server, I found the next two things, when calling it through the nginx proxy, there are this two headers:
GET /v1/menu/esp.json HTTP/1.0
connection: close
When calling it directly, there are this two headers
GET /v1/menu/esp.json HTTP/1.1
connection: keep-alive
Given this, I thought that the restify server was delaying the next call because it was too soon to give access to a new one.
So I did what it was necessary to make nginx to pass exactly the same headers. The configuration then was:
upstream services
{
server localhost:8989;
keepalive 100;
}
server {
listen 444;
server_name localhost;
location /v1/
{
proxy_http_version 1.1;
proxy_set_header Host localhost:8989;
proxy_set_header Connection keep_alive;
proxy_pass http://services;
}
}
I have got it to pass exactly the same headers to the nodejs restify server, but the behaviour is exactly the same than before.
I'm using the windows versions of both, nodejs and nginx.
I patched it using
proxy_connect_timeout 2s;
As someone else did here http://forum.nginx.org/read.php?15,239760,247173
It seems to be an already known issue.