Nginx websocket 502 gateway incorreto

4

Estou tentando usar o nginx como proxy para o servidor nodejs do websocket, mas estou sempre obtendo o 502 gateway ruim.

minha configuração de domínio:

upstream server {
  server 127.0.0.1:8090;
}

server {
 listen 8085;
 server_name server.cz server;
 ssl on;
 #ssl_certificate /etc/ssl/server/server.cz.pem;
 ssl_certificate /etc/ssl/server/server.cz.crt;
 ssl_certificate_key /etc/ssl/server/server.cz.key;

 access_log /var/log/nginx/server.log;
 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_pass http://server;
  proxy_redirect off;

  #WEBSOCKET
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
 }
}

Estou testando isso com o curl:

curl -i -N -vv -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: server.cz" -H "Origin: https://server.cz" -k https://127.0.0.1:8085

isso resultará com o 502 gateway incorreto resultado completo: link

Se eu tentar isso diretamente no servidor nodejs, tudo funcionará bem.

Log do Nginx:

[error] 4083#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: server.cz, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8090/", host: "server.cz"

server.log

"GET / HTTP/1.1" 502 172 "-" "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3"
    
por zajca 07.04.2014 / 14:07

0 respostas