Webpack-serv hmr不能与WebSocket的Nginx代理一起使用

时间:2018-08-10 05:14:15

标签: nginx webpack https websocket webpack-serve

我已经将nginx设置为本地开发环境的代理。我也将webpack-serve用于本地开发人员,并且已经设置了本地ssl证书。我的网站正在运行,但是HMR出现了问题。

当Web套接字尝试连接时,我看到此错误

WebSocket connection to 'wss://local.way.com:7879/' failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR

我不知道这是证书还是nginx设置问题。

server {
  listen      7879 ssl;
  server_name local.way.com;

  ssl_certificate      /usr/local/way-fe/config/proxy/ssl/certificate.crt;
  ssl_certificate_key  /usr/local/way-fe/config/proxy/ssl/certificate.key;
  ssl_session_timeout  5m;
  ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
  ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA;
  ssl_prefer_server_ciphers on;

  location / {
    proxy_pass http://websocket;
    proxy_http_version 1.1;
    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_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Forwarded-Proto $proxy_protocol_port;
  }
 }


upstream websocket {
  server local.way.com:7879;
}

和webpack-serve配置

module.exports = {
  clipboard: true,
  host: 'local.way.com',
  port: 7878,
  'https-cert':
    '/usr/local/way-fe/config/proxy/ssl/certificate.crt',
  'https-key':
    '/usr/local/way-fe/config/proxy/ssl/certificate.key',
  hotClient: {
    port: 7879,
    https: true,
  },
};

0 个答案:

没有答案