vue配置websocket 使用nginx部署无法连接?

关键一:vue配置

'/ws': {
         target: process.env.BASE_URL,
         changeOrigin: true, //开启代理
         ws: true, // 是否启用websockets
         pathRewrite: {
             '^/ws': ''
          }
       }

关键二:nginx配置

#nginx配置websocket
  location /ws {
          proxy_pass http://localhost:8881/ws/; #websocket地址
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
  }

配置完成后重启再测试!

猜你喜欢

转载自blog.csdn.net/weirdo_world/article/details/121512146