和一个
服务器。取决于
子域
现在我想用套接字.io来自另一个地方。
但当我发出声音或听到声音时,它就不起作用了。
我没有得到任何例外,但事件不会触发。
后端代码:
io.set('origins', '*:*');
io.on('connection', function (client) {
console.log(client.id + " joined!"); //event fired
client.on('helloworld', function () {
console.log(client.id + " said hello!"); //event not fired
});
}
前端代码:
var io = io("https://subdomain.example.com");
io.emit("helloworld");
Nginx脚本:
server{
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/subdomain.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/subdomain.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
server_name subdomain.example.com;
location / {
limit_conn addr 10;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:7005/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Access-Control-Allow-Origin "*";
proxy_set_header Access-Control-Allow-Headers "origin, x-requested-with, content-type";
proxy_set_header Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS";
}
}
我尝试过的可能性:
Socket.io + NodeJS + Nginx + SSL
Cross-domain connection in Socket.IO
Socket.io + Node.js Cross-Origin Request Blocked