E
E
ennet2016-04-05 14:21:28
Nginx
ennet, 2016-04-05 14:21:28

How to connect Nginx + nodejs so that put and post do not give a 504 error or another?

Hey! I have a site on nodejs and I want everything to go through the nginx proxy. My config:

upstream nodejs {
server localhost:3000;
}

server {
  listen 80;
  server_name localhost;
  root /home/dev/myApp;

  location / {
    try_files $uri $uri/ @nodejs;
  }
  error_log /var/log/nginx/myApp.error.log;


  location @nodejs {
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_pass http://nodejs;
    proxy_set_header Host $host ;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

Everything is fine with statics, but when I send POST and PUT it gives me the following in the logs
2016/04/05 14:04:38 [error] 16318#0: *6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.1.112, server: localhost, request: "POST /login HTTP/1.1", upstream: "http://127.0.0.1:3000/login", host: "myApp.dev.lan", referrer: "http://myApp.dev.lan/login"

at what on simple localhost:3000 only with nodejs everything works out great.
Tell me where to look. to solve the problem? scoured the internet and found nothing. I would appreciate that. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2016-04-05
@ennet

Try adding these lines to location @nodejs:

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';

I have a similar config, differs only in this one, and it works. Don't forget to restart nginx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question