@saymeit

Websocket за Apache и Nginx, теряются заголовки, как исправить?

Приветствую! Есть такая проблема. Apache слушает на внешнем ip и проксирует все запросы вида /test в nginx(на внутреннем ip), который проксирует из локейшена /city-dashboard в приложение с вебсокетом. В конфиге Apache:
ProxyRequests On
	ProxyPreserveHost On
	   <Location /test>
              ProxyPass "https://127.0.0.1:443"
              ProxyPassReverse "https://127.0.0.1:443"
              Allow from All
              Header set Connection "upgrade"
              Header set Upgrade "websocket"
           </Location>


nginx config: on nginx.conf:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
 } 

   map $http_sec_websocket_key $upgr {
    ""      "";           # If the Sec-Websocket-Key header is empty, send no upgrade header
    default "websocket";  # If the header is present, set Upgrade to "websocket"
   }

   map $http_sec_websocket_key $conn {
    ""      $http_connection;  # If no Sec-Websocket-Key header exists, set $conn to the incoming Connection header
    default "upgrade";         # Otherwise, set $conn to upgrade
  }
include /etc/nginx/conf.d/*.conf; on default.conf


default.conf:
location /city-dashboard {
     rewrite ^/city-dashboard\/(.*)$ /$1 break;
     proxy_pass http://127.0.0.1:5001;
     proxy_set_header Host $host;
     proxy_http_version 1.1;
     #proxy_set_header upgrade $upgr;
     proxy_set_header Upgrade $upgr;
     #proxy_set_header Connection $conn;
     proxy_set_header Connection "Upgrade\n\r";
     proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
     #add_header Upgrade websocket;
     #add_header Connection Upgrade;
     proxy_read_timeout 100;
     proxy_redirect off;
     proxy_set_header        X-Forwarded-Proto $scheme;
     add_header              Front-End-Https   on;
   }

Request headers:
GET wss://example.com:4443/test/city-dashboard/stream HTTP/1.1
Host: example.com:4443
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: https://example.com:4443
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Sec-WebSocket-Key: RlhNyYNipJ1RUOU7nl4xMA==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

Response headers:
HTTP/1.1 101 Switching Protocols
Server: nginx/1.8.0
Date: Sat, 22 Aug 2015 10:05:02 GMT
Sec-WebSocket-Accept: e7UKY/y5mIi8RTmhLQgFJ566dfo=


В заголовках ответа не хватает Upgrade и Connection, если делать по руководству с сайта nginx, то получаю ошибку 400 и вебсокеты все равно не отрабатывают. Убрать из этой цепочки Apache не получится, потому как он находится у другой организации. Может кто с таким сталкивался и предложит какие-нибудь воркэраунды? или просто какие-нибудь решения, чтобы заставить это работать.
  • Вопрос задан
  • 1203 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы