Generel
Request URL:ws://game.meiph.cn/ssb/websocket
Request Method:GET
Status Code:404
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://game.meiph.cn
Access-Control-Expose-Headers:Set-Cookie
Connection:keep-alive
Content-Encoding:gzip
Content-Language:en
Content-Type:text/html;charset=utf-8
Date:Tue, 21 Feb 2017 07:55:40 GMT
Server:nginx
Transfer-Encoding:chunked
X-Powered-By:nutz/1.r.59-SNAPSHOT <nutzam.com>
Request Headers
view source
Accept-Encoding:gzip, deflate, sdch
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:no-cache
Connection:Upgrade
Cookie:sid=plijvjadpihborilfqo5d40p6f
Host:game.meiph.cn
Origin:http://game.meiph.cn
Pragma:no-cache
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
Sec-WebSocket-Key:tMn0hCbsPTbuTbB2w2hwxA==
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
28 回复
pom.xml文件中为什么有三处对websocket的导入,有什么不同吗?为什么有多个dependencies依赖?
</dependency>
</dependencies>
<version>2.9.1</version>
<dependencyManagement>
<dependencies>
<dependency>
配置一个artifacts,然后会在 out目录下面生成 web工程文件,我直接把web工程文件,拷贝到 服务器上tomcat的webapp里去了。
然后有更新,就拷贝更新的class文件。
我用的是windows测试机
在mainsetup.init的末尾加上这句试试
ServerContainer sc = (ServerContainer)nc.getServletContext().getAttribute(ServerContainer.class.getName());
if (sc != null)
try {
sc.addEndpoint(NutzbookWebsocket.class);
}
catch (DeploymentException e) {
e.printStackTrace();
}
是不是nginx没配好, 贴配置看看,需要额外设置的
location / {
proxy_http_version 1.1;
client_max_body_size 10m;
proxy_pass http://nutz;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect http:// https://;
#add_header Access-Control-Allow-Origin "*";
proxy_set_header Upgrade $http_upgrade; // 这个
proxy_set_header Connection $http_connection; // 还有这个
add_header Strict-Transport-Security max-age=63072000;
add_header X-Content-Type-Options nosniff;
}
server {
listen 80;
server_name baidu.com;
#charset koi8-r;
access_log logs/ssu8.cn.access.log main;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
root D:/soft/ssu8/webapps/ROOT;
expires 30d;
}
location ~ "^/ssb/user/[^\/]+/[^\/]+" {
return 605;
}
location / {
proxy_pass http://localhost:8082;
proxy_set_header X-Real-IP $remote_addr;
}
}
是的, 加上
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; // 这个
proxy_set_header Connection $http_connection; // 还有这个
如果没有配置proxy_read_timeout和proxy_send_timeout, 那也得加上
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_pass http://localhost:8082;
proxy_set_header X-Real-IP $remote_addr;
}
这么配置后,重启了nginx和tomcat,没效果呀
还需要看看请求是否已经到达NutFilter, 会打印 no action found 之类的就对了
timeout 起码设置1小时.
proxy_send_timeout 1h;
proxy_read_timeout 1h;
终极解决方案:
nginx配置
server {
listen 80;
server_name aa.xx.bb;
#charset koi8-r;
access_log logs/ssu8.cn.access.log main;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
root D:/soft/ssu8/webapps/ROOT;
expires 30d;
}
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_send_timeout 1h;
proxy_read_timeout 1h;
proxy_pass http://localhost:8082;
proxy_set_header X-Real-IP $remote_addr;
}
}
tomcat版本:apache-tomcat-9.0.0.M11
请保证tomcat服务下,lib中有tomcat-websocket.jar和websocket-api.jar,
nginx配置不正常或者没有对应的jar都不能正常的连接websocket
添加回复
请先登陆