部署 Rails app 时用到了 gem 'websocket-rails'
的standalone
模式
http://128.199.208.206/
在同一台 ubuntu 14.04 上装的 Redis
,port:6379
JS 用 dispatcher = new WebSocketRails("#{hostname}:3001/websocket");
出错返回 500
WebSocket connection to 'ws://128.199.208.206/websocket' failed:
Error during WebSocket handshake: Unexpected response code: 500
命令行 telnet my_server_host 80
GET /websocket HTTP/1.1
Host:128.199.208.206
Connection:Upgrade
Upgrade:WebSocket
会返回一个 类似 development 模式的错误页面:
Mysql2::Error
Access denied for user 'root'@'localhost' (using password: YES)
mysql2 (0.3.18) lib/mysql2/client.rb:70:in `connect'
mysql2 (0.3.18) lib/mysql2/client.rb:70:in `initialize'
activerecord (4.2.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
activerecord (4.2.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
....
==== 我好像搜不到有什么返回 500 值的问题,是不是服务器端的设置有问题 好难,有没有人用过这个 gem,还是你们都用了 faye。。。 找不到什么和这有关的 Log 信息。。 下面是部分配置文件,
#config/database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
timeout: 5000
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
username: root
password: 123456789
database: campusOrders_development
test:
<<: *default
database: campusOrders_test
production:
<<: *default
database: campusOrders_production
username: root
password: 1236******
#config/initializers/websocket_rails.rb
#config.log_level = :debug (把这个设成 :debug 然后重启 websocket server 和 nginx 好像还是没有什么错误信息)
config.standalone = true
#config.standalone_port = 3001 (确认已经运行在默认端口3001上了)
config.synchronize = false
config.daemonize = true
config.redis_options = {:host => 'localhost', :port => '6379'}
#/etc/nginx/sites-enabled/campusorders.com.conf
server {
listen 80 default;
server_name campusorders.com;
root /var/www/campusorders.com/master/public;
passenger_enabled on;
rails_env production;
location /websocket {
proxy_pass http://localhost:3001/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}