尝试从nginx后面的feathersjs + socket.io服务器,它没有安装在根目录下。 大部分的feathersjs可以正确configuration,但在尝试调用socket.io的pathconfiguration时遇到了困难,例如http://socket.io/docs/server-api/#server#path(v:string):server
nginxconfiguration:
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)
之后调用它时是socketio.listen(server)
。 v1.3.3
-socketio模块的v1.3.3现在允许传递一个选项对象 ,让您设置路径。 虽然为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 }));