我有一个具有 nginx 和 nodejs 服务器的服务器系统。根据子域,它将通过proxy_pass被“转发”到正确的NodeJS应用。
现在我想从另一个来源使用Socket.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