尝试从未安装在根目录下的nginx后面提供feathersjs + socket.io。大多数feathersjs可以正确配置,但是在尝试调用socket.io的路径配置时遇到困难,即http://socket.io/docs/server-api/#server#path(v:string):server
Nginx的配置:
upstream socket_nodes {
ip_hash;
server localhost:19090 ;
}
server {
...
location /spx {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://socket_nodes;
# root html;
# index index.html index.htm;
}
}
和node.js代码:
var feathers = require('feathers');
var app = feathers();
app.configure(feathers.rest());
// Configure Socket.io real-time APIs
app.configure(feathers.socketio(function(io){
io.path('/spx/socket.io');
}));
...但是当浏览器点击
/spx/socket.io/socket.io.js
时,我仍然得到404。有任何想法吗?
最佳答案
如评论中所述,在io.path
之后调用socketio.listen(server)
时,它似乎不起作用,这在Feathers中会发生。现在,feathers-socketio模块的v1.3.3
可以传递options object,它允许您设置路径。尽管是为Feathers 2构建的,但它在Feathers 1.x(而不是feathers.socketio
)中也可以正常工作:
var feathers = require('feathers');
var socketio = require('feathers-socketio');
var app = feathers();
app.configure(feathers.rest());
// Configure Socket.io real-time APIs
app.configure(socketio({
path: '/spx/socket.io/'
}, function(io){
// Do other things here
}));