2016-09-02 7 views
2

레일 5, Nginx 및 Puma로 서버를 구성하려고합니다. 응용 프로그램이 잘 실행되고 있지만 Actioncable이 production.rb에서 레일에서 아래Actioncable Nginx 및 Puma WebSocket 핸드 셰이크 : 예기치 않은 응답

WebSocket connection to 'ws://server_name.com/cable' failed: 
Error during WebSocket handshake: Unexpected response code: 200 

내의 nginx 설정입니다

upstream app { 
    server unix:/tmp/app.sock fail_timeout=0; 
} 

server { 
    listen  80; 
    server_name server_name.com; 
    try_files $uri/index.html $uri @app; 
    client_max_body_size 100M; 
    location @app { 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 
     proxy_pass http://app; 
     client_max_body_size 10M; 
    } 

    location /cable { 
     proxy_pass http://app/; 
     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection "Upgrade"; 
    } 

    location ~ ^/(assets|uploads)/ { 
     root assets_path; 
     gzip_static on; 
     expires max; 
     add_header Cache-Control public; 
     add_header ETag ""; 
     break; 
    } 
    error_page 500 502 503 504 /500.html; 
} 

을주고, 나는 다음과 같은 설정을했다.

config.action_cable.url = 'ws://server_name.com/cable' 

도움이 되겠습니다.

+0

'ws : // server_name.com/cable/websocket'을 사용하여 시도하십시오. – Magnuss

+0

그게 작동하지 않습니다. –

+0

해결 방법을 찾았습니까? 나는 이것도 붙어있다. –

답변

0

사용해보십시오, 또한

location /cable { 
    proxy_pass http://app; # not http://app/; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "Upgrade"; 
} 

그리고

당신이 SSL을 추가 할

1

시도가없는 경우에 당신이 당신의 production.rb에 config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]이 있는지 확인하십시오 :

config.action_cable.allowed_request_origins = ['*'] 
config.action_cable.disable_request_forgery_protection = true 

을에를 config/environments/production.rb 파일

저와 함께 작동하면를 확인할 수 있습니다.도 있습니다. and this question