Websocket trabalhando dentro da LAN, mas erro 502 do cliente remoto com o proxy nginx

1

Eu tenho este problema realmente frustrante onde meu servidor que consiste em um proxy reverso nginx e django / channels / daphne websocket está funcionando dentro da LAN local, mas de um cliente remoto somente a conexão websocket não pode ser mantida.

Eu acredito que é um problema de configuração do Nginx, mas parece que não consigo resolvê-lo depois de alguns dias batendo minha cabeça contra a parede.

Em primeiro lugar, minha configuração do Nginx:

server {
listen 80;
server_name app.server.domain;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/program;
}

# uWSGI
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/program.sock;
}
# Daphne
location /socket/ {
    proxy_pass http://127.0.0.1:8001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade 'websocket';
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connect_timeout 3600s;
    proxy_send_timeout 3600s;
    proxy_read_timeout 3600s;
}

}

no nginx error.log, eu recebo:

2018/04/20 17:12:30 [error] 15479#15479: *67 recv() failed (104: Connection reset by peer) while reading upstream, client: 172.16.0.1, server: scan.contac.cl, request: "GET /socket/ HTTP/1.1", upstream: 
"http://127.0.0.1:8001/socket/", host: "app.server.domain"

se você ngrep o servidor mostrado:

#####
T 172.16.0.1:36458 -> 172.16.2.116:80 [AP]
  GET /socket/ HTTP/1.1..Host: app.server.domain..User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0..A
  ccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8..Accept-Language: en-US,en;q=0.5..Accept-Encoding: gzip, deflate..
  Sec-WebSocket-Version: 13..Origin: http://app.server.domain..Sec-WebSocket-Extensions: permessage-deflate..Sec-WebSocket-Key: ayyjtzvGPTiVuF
  IZduaBTQ==..Pragma: no-cache..Cache-Control: no-cache..X-Forwarded-For: 191.XXX.XXX.201..X-Forwarded-Host: app.server.domain..X-Forwarded-Ser
  ver: app.server.domain..Connection: Keep-Alive....                                                                                          
#####
T 172.16.0.1:36460 -> 172.16.2.116:80 [AP]
  GET /socket/ HTTP/1.1..Host: app.server.domain..User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0..A
  ccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8..Accept-Language: en-US,en;q=0.5..Accept-Encoding: gzip, deflate..
  Sec-WebSocket-Version: 13..Origin: http://app.server.domain..Sec-WebSocket-Extensions: permessage-deflate..Sec-WebSocket-Key: PEV955vUzQd5Q0
  /WY8wRrQ==..Pragma: no-cache..Cache-Control: no-cache..X-Forwarded-For: 191.XXX.XXX.201..X-Forwarded-Host: app.server.domain..X-Forwarded-Ser
  ver: app.server.domain..Connection: Keep-Alive....                                                                                          
#####
T 172.16.0.1:36462 -> 172.16.2.116:80 [AP]
  GET /socket/ HTTP/1.1..Host: app.server.domain..User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0..A
  ccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8..Accept-Language: en-US,en;q=0.5..Accept-Encoding: gzip, deflate..
  Sec-WebSocket-Version: 13..Origin: http://app.server.domain..Sec-WebSocket-Extensions: permessage-deflate..Sec-WebSocket-Key: 8BpG9osIwqftJf
  H2zrW1-ig==..Pragma: no-cache..Cache-Control: no-cache..X-Forwarded- For: 191.XXX.XXX.201..X-Forwarded-Host: app.server.domain..X-Forwarded-Ser
  ver: app.server.domain..Connection: Keep-Alive....                                                                                          
#####
T 172.16.2.116:80 -> 172.16.0.1:36500 [AP]
  HTTP/1.1 101 Switching Protocols..Server: nginx/1.12.1 (Ubuntu)..Date: Fri, 20 Apr 2018 21:36:52 GMT..Connection: upgrade..Upgrade: WebSo
  cket..Sec-WebSocket-Accept: eDUwiFKKbT4ojtR+gWSvzRGNV3k=....                                                                             
########

e ngrep, o cliente mostra:

  T 186.XXX.XXX.XXX:80 -> 192.XXX.XXX.XXX:35010 [AP]
  HTTP/1.1 502 Proxy Error..Date: Fri, 20 Apr 2018 20:11:40 GMT..Content-Length: 475..Connection: close..Content-Type: text/html; charset=i
  so-8859-1....<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">.<html><head>.<title>502 Proxy Error</title>.</head><body>.<h1>Proxy Error
  </h1>.<p>The proxy server received an invalid..response from an upstream server.<br />..The proxy server could not handle the request <em
  ><a href="/socket/">GET&nbsp;/socket/</a></em>.<p>.Reason: <strong>Error reading from remote server</strong></p></p>.<hr>.<address>Apac
  he/2.2.15 (CentOS) Server at app.server.domain Port 80</address>.</body></html>.

Qualquer ajuda para resolver isso seria imensamente apreciada !!!!!! Eu basicamente bato um obstáculo.

    
por Chris 20.04.2018 / 23:30

1 resposta

1

Olhando para as respostas dos servidores, parece que você provavelmente tem um proxy reverso extra em algum lugar. Está em Apache/2.2.15 (CentOS) e você precisa reconfigurá-lo também, não apenas o nginx/1.12.1 (Ubuntu) .

    
por 21.04.2018 / 00:21