Comments (4)
目前確定問題在於 server 前掛了層 cloudflare 及 aws ELB,導致 websocket connect failed
繞過 cloudflare,直接連到server就正常了
Rails.application.config.action_cable.allowed_request_origins = 'http://ip-address'
chrome url 打 ip-address 而不是 domain_url
from ama.
因為 cloudflare 寫 support websocket in any plan
估且先相信它了
試了以下幾個做法
想讓 ELB support websocket
照以下的教學在 ELB 多加了個 listener,並用 aws-cli 設定好了
https://blog.jverkamp.com/2015/07/20/configuring-websockets-behind-an-aws-elb/
但沒有效
想讓websocket直接跳過 ELB 跟 server 溝通,在 config/environments/production.rb 中加了
Rails.application.config.action_cable.allowed_request_origins = [ 'https://socket.amazing-tutor.com', /https:\/\/socket.amazing-tutor.*/ ]
config.action_cable.url = "wss://socket.amazing-tutor.com/cable"
layout 中加了 <%= action_cable_meta_tag %>
並在 nginx conf 的 server name 加了 socket.amazing-tutor.com
然後將 socket.amazing-tutor.com 的 DNS 指向 server ip,而非 ELB ip
但仍然是錯誤的
WebSocket connection to 'wss://socket.amazing-tutor.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 503
WebSocket connection to 'wss://socket.amazing-tutor.com/cable' failed: WebSocket is closed before the connection is established.
想將 config.action_cable.url = "ws://server-ip/cable"
讓 websocket 直接與 server 溝通
但因為網頁是 https:// ,所以不能使用 ws,必須要有加密的 wss
目前 https 是 cloudflare 提供,所以似乎不能不經過 cloudflare
from ama.
目前成功的做法是,DNS 直接指向 server-ip,不論 http, https, websocket 都不經過ELB
不過 cloudflare 仍然保留
from ama.
我有遇到和你類似的問題,但因為架構跟你的有些不同,所以解決的方式也有些不同,但或許可以參考一下
我是透過 elastic beanstalk 部署我的 Rails Application ,並且使用 Nginx + Puma 而不是 Phusion
SSL 的設定我是在 load balancer 上,其中 80, 443 的 port 原本是使用 http, https 作為通訊協定,要分別改成 tpc, ssl 作為通訊協定
nginx 的設定檔
client_max_body_size 1G;
server_names_hash_bucket_size 128;
upstream backend {
server unix:///var/run/puma/my_app.sock;
}
server {
listen 80;
listen 443 ssl;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server_name YOUR_SERVER_NAME;
large_client_header_buffers 8 32k;
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_set_header X-Forwarded-Proto https;
proxy_buffers 8 32k;
proxy_buffer_size 64k;
proxy_pass http://backend;
proxy_redirect off;
location /assets {
root /var/app/current/public;
}
# enables WS support
location /cable {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
}
}
from ama.
Related Issues (20)
- 想請問一下 遠端機器環境建置問題 HOT 5
- fork gem 後指定 gem source 為自己的 github,capistrano deploy bundle 錯誤 HOT 10
- 請教Devise的問題 HOT 1
- 實作 Agile Web Development With Rails 4 HOT 5
- Agile Web Development With Rails 4 Chapter 11.5
- Agile Web Development With Rails 4 Chapter 11.5
- 如何直接取得hash的size並作運算 HOT 2
- About rails breadcrumbs gem
- Rails5 WebSocket 偶爾 handshake 404 HOT 2
- 請問關於加密的問題 HOT 2
- 面試題目參考資料 HOT 1
- 請問為何 better_errors 無法在 Rails 4.2.0 + Ruby 2.2.0 上使用? HOT 2
- 詢問 space 和 tab 轉換工具 HOT 6
- 請問要如何實做複選框+背景新增值的功能,或是有那種複選tagging的功能? HOT 11
- 為什麼 deep_dup 實作卻只是呼叫 dup HOT 1
- 請教一下,我把專案從Rails 4.2升級到 5.2,忽然Devise就無法登出了!!! HOT 5
- 請教一下,如何讓一個驗證失敗後就停住? HOT 2
- 想請教一下,如何讓事件點進去能在 Daterangepicker 顯示正確日期? HOT 3
- 商务
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ama.