我想把nodejs绑定到一个url,像这样:http://myproject.com/nodejs/
目前,我在端口8080节点。
我有nginx配置:
upstream app {
server 127.0.0.1:8080;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
root /home/myproject/www;
index index.html index.htm;
server_name myproject.com;
location /nodejs/ {
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_pass http://app/;
proxy_redirect off;
}
}
当我打开URL时,我得到:
Welcome to socket.io.
连接正常。
但是,当我尝试在我的网站连接,我得到这个:
GET http://myproject.com/socket.io/1/?t=1385767934694 404 (Not Found) socket.io.js:1659
这是我的网站行做连接:
var socket = io.connect('http://myproject.com/nodejs/');
我该怎么做?
6条答案
按热度按时间1l5u6lss1#
我得到一个错误=/
这是我的nginx服务器端配置:
如果我不加:
我得到这个错误:
我在这个链接中看到了这个conf:http://mattpatenaude.com/hosting-chatroom/
dojqjjoe2#
之前在另一个帖子中回复过:https://stackoverflow.com/a/12904282/2324004
不幸的是,Socket.io wiki缺少一些信息,但线索是设置资源:
客户端
服务器
以上是工作(我已经测试了它的时刻)。这一个应该与上面的配置一起工作:
q9yhzks03#
我从来没有遇到过这样的配置开关,允许从URL更改 * socket.io * 部分。但是AFAIK,如果您使用此配置,您的问题将得到解决:
http://michieldemey.be/blog/proxying-websockets-with-nginx-and-socket-io/
sirbozc54#
ou6hu8tu5#
我还不能发表评论,但你确定你没有主机名上的错字吗?
你已经发布了一些代码片段,一切都取决于你配置了什么。
sc4hvdpw6#
这只是WebSocket不工作,如果我从io传输中删除websocket,所有工作正常,我在我的客户端上使用这行:
如果我不编辑这个传输列表,它是工作的,但是,我有一个WebSocket错误,10秒后,客户端使用xhr轮询,它的工作。