2013-07-02 3 views
2

안녕하세요, webservices에 대한 리버스 프록시로 nginx를 구성하려고합니다. 나는 다음과 같은 내 서버를 구성합니다nginx websocket 리버스 프록시 구성

server { 
    listen  80; 
    server_name www.mydomain.com; 

    access_log off; 
    #error_log off; 

    location/{ 
     proxy_pass   http://127.0.0.1:8765; 
     proxy_redirect  off; 

     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection "Upgrade"; 
     proxy_set_header Host $http_host; 

     proxy_buffering off; 
    } 

} 

하지만 난에

웹 소켓 연결을 다음과 같이 클라이언트에서 오류가 'WS : //www.application.com/ws'실패 : 웹 소켓 핸드 셰이크 중에 오류 : 'Connection'헤더 값이 '업그레이드'가 아닙니다.

일부 설정을 잘못했는데 표시되지 않습니다. 나는 보통의 직접 연결을 수행 할 때 클라이언트에 대한

요청 헤더

GET ws://www.talkybee.com/ws HTTP/1.1 
Pragma: no-cache 
Origin: http://www.talkybee.com 
Host: www.talkybee.com 
Sec-WebSocket-Key: Ol+O1IdaLEsHxxWRBt2oqg== 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 
Upgrade: websocket 
Sec-WebSocket-Extensions: x-webkit-deflate-frame 
Cache-Control: no-cache 
Connection: Upgrade 
Sec-WebSocket-Version: 13 

따르고, 내 연결은 작동합니다. 다음은 작업 요청 헤더입니다.

Cache-Control:no-cache 
Connection:Upgrade 
Host:www.talkybee.com:8765 
Origin:http://www.talkybee.com:8765 
Pragma:no-cache 
Sec-WebSocket-Extensions:x-webkit-deflate-frame 
Sec-WebSocket-Key:Y026b/84aUkMxVb0MaKE2A== 
Sec-WebSocket-Version:13 
Upgrade:websocket 
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 
+0

'proxy_pass http : //127.0.0.1 : 8765 /;' – rednaw

+0

@rednaw 동일한 예외가 발생합니다. 나는 현재의 질문으로 구성의 설정을 변경했다. – yilmazhuseyin

+0

클라이언트도'Connection' 헤더를'Upgrade'로 설정하고 있습니까? – rednaw

답변

20

이 문제는 nginx 버전과 관련이 있습니다. 버전을 확인하려면 nginx -v를 확인하십시오. 다음 매개 변수는 1.4 버전 이후에 지원됩니다. 당신이 우분투를 사용하는 경우

# WebSocket support (nginx 1.4) 
proxy_http_version 1.1; 
proxy_set_header Upgrade $http_upgrade; 
proxy_set_header Connection "upgrade"; 

이 단계를 최신 버전을 설치할 수 있습니다

먼저 이전 버전 (https://askubuntu.com/questions/235347/what-is-the-best-way-to-uninstall-nginx) 제거 :

sudo apt-get remove nginx 
sudo apt-get purge nginx 
sudo apt-get autoremove 

그런 다음 새 버전을 설치합니다 (https://launchpad.net/~nginx/+archive/development를) :

sudo add-apt-repository ppa:nginx/development 
sudo apt-get update 
sudo apt-get install nginx 
+0

나는 그 문제가 너무 있지만 내 nginx 서버 (~ $ nginx -v)를 업그레이드하여이 문제를 해결했다. (nginx 버전 : nginx/1.5.1) – yilmazhuseyin

+0

이 문제에 대한 해결책은 websocket에 직접 포트를 연결하는 것이 었습니다. 따라서 내 사이트는 포트 80에 있지만 내 websocket 연결은 포트로 이동합니다 : 8765는 websocket과 같은 도메인 간 제한이 없습니다. – yilmazhuseyin

관련 문제