Nginx设置WebSocket(Wss),以宝塔面板为例,应该很多人需要

分享 未结 精帖 2 88
鹭岛智造
悬赏:20积分
宝塔面板:网站——设置——配置文件 第一行添加: map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream websocket { server 127.0.0.1:8000; #要改成renren_admin后端的端口 } 找到#SSL-END,在这之后添加: #wss协议转发 location /renren_admin/websocket { proxy_pass http://websocket/renren_admin/websocket; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } 之后找到前端工程: window.SITE_CONFIG['apiURL'] = 'https://域名/renren_admin'; window.SITE_CONFIG['socketURL'] ='wss://域名/renren_admin/websocket'; 有个关键点,因为人人开源websocoket是用cookie,所以apiURL和socketURL都必须是在renren_admin(可以是别的名字)下,这两者名字必须一致,否则cookie带不到后台去,会报500,空指针异常。
本帖标签: websocket 宝塔
回帖
  • face[good] face[good] face[good] 虽然已经解决了,当时也是费了一番功夫!
    0 回复
  • 有没有出现过这个错误,websocket已经连接成功了,表面上都正常,但是其他用户时不时的会报出这个错误,排查了半天也没法复现 错误信息 [pre] [http-nio-8080-exec-11] ERROR info.boyun.websocket.WebSocketServer - null java.io.EOFException: null at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1235) at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1143) at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:72) at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171) at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151) at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148) at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:59) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) [/pre]
    0 回复