JBolt平台最近加入了完整的JBolt-websocket解决方案,适用于IOT、智能家居、楼宇智控平台的开发。
在本地调试没问题后部署到线上发现websocket不通:
我demo站点部署使用的nginx->undertow反向代理
具体配置nginx->undertow反向代理的教程我之前写过:
server { listen 80; server_name demo.jbolt.cn; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://127.0.0.1:8082; proxy_connect_timeout 300s; proxy_send_timeout 900; proxy_read_timeout 900; proxy_buffer_size 32k; proxy_buffers 4 64k; #proxy_buffering off; proxy_busy_buffers_size 128k; proxy_redirect off; proxy_hide_header Vary; proxy_set_header Accept-Encoding ''; proxy_set_header Referer $http_referer; proxy_set_header Cookie $http_cookie; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location = /50x.html { root html; } }
那么问题就出在Nginx配置上了,我只配置了 :
但是websocket的地址是ws://demo.jbolt.cn/websocket.ws
所以应该针对这个也做个部署:
server { listen 80; server_name demo.jbolt.cn; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://127.0.0.1:8082; proxy_connect_timeout 300s; proxy_send_timeout 900; proxy_read_timeout 900; proxy_buffer_size 32k; proxy_buffers 4 64k; #proxy_buffering off; proxy_busy_buffers_size 128k; proxy_redirect off; proxy_hide_header Vary; proxy_set_header Accept-Encoding ''; proxy_set_header Referer $http_referer; proxy_set_header Cookie $http_cookie; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /websocket.ws { proxy_pass http://127.0.0.1:8082; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; } location = /50x.html { root html; } }
这样nginx重载配置后 刷新看效果:
有了新通知也会及时提醒了!!
JBolt极速开发平台,省心,省事儿,极速开发,JFinal社区近400家企业的选择!
微信:18766735632
推荐:
【教程】JFinal-Event异步执行JBolt中服务端websocket推送
项目:JBolt极速开发平台