WebSocket connection to 'ws://localhost/aa/ws1' net::ERR_CONNECTION_REFUSED
来源:互联网 发布:淘宝上买steam游戏商家 编辑:程序博客网 时间:2024/05/20 18:02
在项目中使用了websocket 进行数据推送 在本地访问没问题 部署到服务器上之后报 WebSocket connection to 'ws://localhost/aa/ws1' net::ERR_CONNECTION_REFUSED
很是郁闷!!
后面发现服务器上使用了nginx,发现也需要在nginx中配置websocket
前台
function init(){
if ('WebSocket' in window) {
websocket = new WebSocket("ws://localhost/aa/ws1");
} else if ('MozWebSocket' in window) {
websocket = new MozWebSocket("ws://localhost/aa/ws1");
} else {
websocket = new SockJS("http://localhost/aa/ws1/sockjs");
}
websocket.onopen = function() {
console.log('open');
};
后台
registry.addHandler(new MyHandler(), "/ws1");
registry.addHandler(new MyHandler(), "/ws1/sockjs").addInterceptors(new MyHandlShakeInterceptor()).withSockJS();
nginx配置
upstream test{
server localhost:8080;
}
location /aa/ws1 {
proxy_pass http://test;
proxy_redirect off;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
解决~~
- WebSocket connection to 'ws://localhost/aa/ws1' net::ERR_CONNECTION_REFUSED
- WebSocket connection to 'ws://localhost/Test/socket' failed: Error in connection establishment: net:
- WebSocket connection to 'ws://localhost:8080/xxx' failed: Error during WebSocket handshake...
- WebSocket connection to 'ws://.../sockjs/pushWords/635/78epgvv8/websocket'
- Failed to load resource: net::ERR_CONNECTION_REFUSED
- websocket 无法找到ws://localhost:8080/WebSocket/message
- JSON.stringify( new WebSocket("ws://localhost:8080/websocket.do"))
- java.net.ConnectException: Call From localhost/127.0.0.1 to localhost:8020 failed on connection
- 102 (net::ERR_CONNECTION_REFUSED)
- net::ERR_CONNECTION_REFUSED解决办法
- 跨域net::ERR_CONNECTION_REFUSED解决方法
- Call to localhost/127.0.0.1:9000 failed on connection exception:java.net.ConnectException.拒绝连接
- Call to localhost/127.0.0.1:9000 failed on connection exception:java.net.ConnectException
- Call to localhost/127.0.0.1:9001 failed on connection exception: java.net.ConnectException: Connecti
- to localhost:8020 failed on connection exception: java.net.ConnectException: 拒绝连接
- Call to localhost/127.0.0.1:9000 failed on connection exception:java.net.ConnectException
- Call to localhost/127.0.0.1:9000 failed on connection exception:java.net.ConnectException
- ajax错误处理 net::ERR_CONNECTION_REFUSED
- strStr II
- websocket断开重连解决方案,基于子慕大诗人博客修改 健壮强化版
- sklearn 精确率、召回率
- 我是被淘宝给气到了,不在使用这个玩意,泄露我的信息
- Java—API
- WebSocket connection to 'ws://localhost/aa/ws1' net::ERR_CONNECTION_REFUSED
- springmvc-annotation注解式开发(表单封装)
- 配置Java环境
- 使用Ynm3k的iosMonkey脚本测试iOS应用的稳定性
- Spring框架中的设计模式(五)
- 限流模式-Guava的RateLimiter
- Coursera Machine Learning 第二周编程全套满分题目+注释 ex1+ex1_multi(包括选做Optional)
- Centos6.5 下Docker的安装
- easyui中的tree的图标更改