location /wss/
{
proxy_pass http://127.0.0.1:7070;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
rewrite /wss/(.*) /$1 break;
proxy_redirect off;
}
function socketIo() {
console.log('socketIo');
var socket = io('https://www.***.com/wss/');
// uid可以是自己網(wǎng)站的用戶id,以便針對uid推送以及統(tǒng)計(jì)在線人數(shù)
uid = "user_"+localStorage.id;
// socket連接后以uid登錄
socket.on('connect', function() {
// 驗(yàn)證一下
console.log('socket 連接 '+uid);
socket.emit('login', uid);
});
// 后端推送來用戶數(shù)據(jù)時
socket.on('openAccount', function(msg) {
msg = msg.replace(/"/g, '"');
console.log("openAccount收到消息:"+msg);
msg = JSON.parse(msg);
if (!msg) {
console.log('服務(wù)端推送數(shù)據(jù)有誤');
return;
}
// console.log("openAccount收到消息:"+JSON.stringify(msg));
localStorage.openstep = msg.openstep;
localStorage.account_state = msg.account_state;
if (msg.account_state == 1) {
console.log('account_state => '+localStorage.account_state);
app.toast('開戶成功!');
} else if (msg.account_state == 3) {
console.log('account_state => '+localStorage.account_state);
app.toast('開戶失敗,請重新提交!');
}
var myCenter= plus.webview.getWebviewById('myCenter');
setTimeout(function() {
//延遲2秒執(zhí)行,防止重復(fù)
mui.fire(myCenter, 'loadUserInfo');
}, 2000);
});
}
新版本PHPSocket.io已經(jīng)支持 SSL,可以不用nginx做代理了。
參考PHPSocket.IO手冊
https://github.com/walkor/phpsocket.io/tree/master/docs/zh#支持sslhttps-wss