1

我已将 nginx 设置为本地开发环境的代理。我也将 webpack-serve 用于本地开发,以及我设置的本地 ssl 证书。我有网站工作,但我遇到了 HMR 问题。

当网络套接字尝试连接时,我看到了这个错误

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,
  },
};
4

0 回答 0