由于某种原因我的节点服务器无法提供路由/socket.io/socket.io.js,我总是得到404错误.
我尝试编译不同的节点版本(当前是0.6.13,它也在服务器上运行,它实际上工作).
从app.js我得到info: socket.io started并且在尝试调用socket.io.js时没有错误.
我从localhost和端口8000尝试它,我使用快速框架
这是来自app.js的代码:
var express = require('express')
, app = require('express').createServer()
, io = require('socket.io').listen(app, { log: true });
app.listen(8000);
app.configure(function() {
app.use(express.static(__dirname + '/public'));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
io.sockets.on('connection', function (socket) {
// all other stuff here
Run Code Online (Sandbox Code Playgroud) 我有这个错误请求.

德语中的最后一句是指"Firefox无法连接到位于ws:// ......."的服务器.
服务器不会是我认为的问题.
因为这里是nginx配置,因为我觉得有问题!
server {
server_name example.org;
listen 80 default_server;
root /var/www/web;
location / # for symfony2
{
try_files $uri @rewriteapp;
}
location @rewriteapp # for symfony2
{
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/app\.php(/|$)
{
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param HTTPS off;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ ^/socket
{
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
}
Run Code Online (Sandbox Code Playgroud)
nginx版本:nginx/1.4.7
app.js(那就是服务器!)
var …Run Code Online (Sandbox Code Playgroud) 有没有一种在Express 3.0中使用Socket.io会话的好方法?一种以安全的方式获取客户会话ID的方法?这样我就可以向会员特定的会员发送通知,并从会员到会员进行私聊?
我在Express 3.0中使用MySQL商店
问题: 如果我注释掉快速['static']行,代码运行完美.如果我包含它(或更改顺序),应用程序会在响应之前挂起一段时间.
要重新创建: 运行应用程序,加载浏览器并转到127.0.0.1:51783不断刷新页面(或使用curl),控制台将为您提供类似于以下内容的输出:
GET / 1 ms
Run Code Online (Sandbox Code Playgroud)
然后,当超时启动并发送15个请求时,服务器将无响应,您将获得以下信息:
Server Now Unresponsive but requests queued
GET / 35549 ms
Run Code Online (Sandbox Code Playgroud)
app.js
var http = require('http');
var express = require('express');
var app = express.createServer();
app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
app.use(express.bodyParser());
app.use(express['static'](__dirname + '/')); //Comment me and all works perfectly!
app.listen(51783);
http.globalAgent.maxSockets = 500; //doesn't help
setTimeout(function(){
console.log('Server Now Unresponsive but requests queued');
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15].forEach(function(item){
http.request({host:'http://cnn.com', port:80, path:'/null', method:'GET'}, function(res){
}).on('error', function(e){});
});
},5000);
Run Code Online (Sandbox Code Playgroud) node.js ×4
express ×3
socket.io ×3
javascript ×2
nginx ×1
sockets ×1
static ×1
web-services ×1