我正在尝试在客户端使用JSSIP配置Kamailio和WebSocket Secure(wss)。我在kamailio.cfg和tls.cfg上进行了设置,除了允许的端口和重定向。在我的浏览器控制台上,我看到:jssip-3.0.13.js:21334 WebSocket connection to 'wss://mydomain.com:4443/' failed: WebSocket opening handshake was canceled
但是,如果我使用ws('ws://mydomain.com:8080/'
),它就会起作用。
有人知道如何解决这个问题吗?
我生成了证书,但问题仍然存在。我正在使用nodeJS作为服务器。
kamailio.cfg文件:
/ *添加本地域别名* /
别名= “mydomain.com”
listen = udp:private_ip:5060 advertise public_ip:5060
listen = tcp:private_ip:5060 advertise public_ip:5060
listen = tcp:private_ip:5061 advertise public_ip:5061
listen = MY_WS_ADDR广告public_ip:8080
listen = tls:private_ip:4443 advertise public_ip:5061
“#!ifdef WITH_TLS
listen = MY_WSS_ADDR广告public_ip:4443
“#!ENDIF
tcp_connection_lifetime = 3604
tcp_accept_no_cl =是
tcp_rd_buf_size = 16384
/ *要侦听的端口(对于tls,udp,tcp,scrtp或5061默认为5060)* /
“#port = 5060
[...]
“#!define WITH_NAT”
“#!define WITH_MYSQL”
“#!define WITH_AUTH
“#!define WITH_USRLOCDB”
“#!define WITH_TLS”
“#!define WITH_DEBUG”
“#!substdef”!MY_IP_ADDR!my_private_ip!g“
“#!substdef”!MY_DOMAIN!my_public_ip!g“
“#!substdef”!MY_WS_PORT!8080!g“
“#!substdef”!MY_WSS_PORT!4443!g“
“#!substdef”!MY_WS_ADDR!tcp:MY_IP_ADDR:MY_WS_PORT!g“
“#!substdef”!MY_WSS_ADDR!tls:MY_IP_ADDR:MY_WSS_PORT!g“
额外信息 event_route [xhttp:request]等于Kamailio 5.0 docs:https://kamailio.org/docs/modules/5.0.x/modules/websocket.html [...]
tls.cfg文件:
[...]
[服务器:默认]
method = TLSv1
verify_certificate = no
require_certificate = yes
private_key = /etc/certs/mydomain.com/key.pem
certificate = /etc/certs/mydomain.com/cert.pem
[...]
[...]
[客户端:默认]
verify_certificate = yes
require_certificate = yes
[...]
使用Javascript:
var socket = new JsSIP.WebSocketInterface('wss://mydomain.com:4443');
var configuration = {
sockets : [ socket ],
uri : 'sip:client@mydomain.com',
password : '******',
};
的NodeJS:
'use strict';
var os = require('os');
var path = require('path');
const https = require('https');
var url = require('url');
const fs = require('fs');
const options = {
key: fs.readFileSync('demoCA/key.pem'),
passphrase: '*********',
cert: fs.readFileSync('demoCA/cert.pem')
};
var app = https.createServer(options, function(req, resp) {
var url_parts = url.parse(req.url);
var path = url_parts.pathname;
console.log(path)
fs.readFile(__dirname + path, function(err, data) {
if(err) {
resp.writeHead(404, {'Content-Type': 'text/html'});
resp.write('Not found');
} else {
resp.writeHead(200, {'Content-Type': 'text/html'});
resp.write(data);
}
resp.end();
});
});
app.listen(443);
AWS
聆听
udp: private_ip:5060 advertise public_ip:5060
tcp: private_ip:5060 advertise public_ip:5060
tcp: private_ip:5061 advertise public_ip:5061
tcp: private_ip:8080 advertise public_ip:8080
tls: private_ip:4443 advertise public_ip:4443
别名:
tls: ip-private_ip.us-west-2.compute.internal:4443
tcp: ip-private_ip.us-west-2.compute.internal:8080
tcp: ip-private_ip.us-west-2.compute.internal:5061
tcp: ip-private_ip.us-west-2.compute.internal:5060
udp: ip-private_ip.us-west-2.compute.internal:5060
如果您需要更多详情,请问我,所以我会编辑我的问题。
答案 0 :(得分:0)
我解决了我的问题。我错过了加载一些模块和路由器。
我看到这个文件为例: https://gist.github.com/jesusprubio/4066845但重要的是要知道 每个模块开始“mi”他们不支持Kamailio 5.0。 您需要替换相对于版本5.0的模块。
我使用此网站生成证书:certbot.eff.org/#ubuntuxenial-nginx
我希望对某人有所帮助。