Socketio无法通过https连接

时间:2018-11-22 15:34:39

标签: node.js ssl nginx socket.io feathersjs

我正处于我的节点/羽毛应用程序的最后阶段。当我在服务器上运行一个应用程序时,作为守护进程的HTTP正在运行nginx,所有这些都很好用。当我在重新加载页面后将certbot用于centos7 / nginx以使用SSL时,我的socket.io无法加载-错误:安全错误。我使用公共域,并为此域创建了一个证书。

我在客户端使用以下配置:

var socket = io({transports: ['websocket']});

    var app = feathers()
      .configure(feathers.hooks())
      .configure(feathers.socketio(socket))
      .configure(feathers.authentication({ storage: window.localStorage }))

app.js

// I added below code to end line of app.js file
const opts = {
  key: fs.readFileSync('./privkey.pem'),
  cert: fs.readFileSync('./cert.pem')
};

const server = https.createServer(opts, app);
app.setup(server);

module.exports = app;

Nginx:

server {

        server_name subdomain www.subdomain;

        location / {

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;

                proxy_pass http://127.0.0.1:3030;
                proxy_redirect off;

        }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/subdomain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/subdomain/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 {
    if ($host = subdomain) {
        return 301 https://$host$request_uri;
    } # managed by Certbot



        listen 80;

        server_name subdomain;
    return 404; # managed by Certbot

}

问题出在哪里?

0 个答案:

没有答案