Handshake failed due to invalid Upgrade header: null 解决方案
2023-09-27 14:27:16 时间
微信小程序webSocket使用,本地开发环境没问题,QA环境报错:
org.springframework.web.socket.server.support.DefaultHandshakeHandler : Handshake failed due to invalid Upgrade header: null
前端报错:
failed: Error during WebSocket handshake: Unexpected response code: 400
经过比较后发现,QA环境使用nginx反向代理服务器忽略了headers中的:Upgrade:websocket。
解决办法:在 Nginx ,location
中添加以下红色代码:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection
"upgrade"
;
1 server { 2 listen 80; 3 server_name localhost; 4 5 6 location / { 7 proxy_set_header X-Real-IP $remote_addr; 8 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 9 proxy_set_header Host $http_host; 10 proxy_set_header X-NginX-Proxy true; 11 12 # prevents 502 bad gateway error 13 proxy_buffers 8 32k; 14 proxy_buffer_size 64k; 15 16 proxy_pass http://127.0.0.1:8080; 17 proxy_redirect off; 18 19 # enables WS support 20 proxy_http_version 1.1; 21 proxy_set_header Upgrade $http_upgrade; 22 proxy_set_header Connection "upgrade"; 23 } 24 }
使得请求中包含Upgrade。
相关文章
- Failed to download metadata for repo ‘docker-ce-stable‘: Cannot download repomd.xml: Cannot download
- failed for get of /hbase/hbaseid, code = CONNECTIONLOSS, retries = 1
- [转]深入理解Docker ulimit(docker容器启动报错library initialization failed - unable to allocate file descriptor table - out of memory问题解决)
- SLF4J: Failed to load class org.slf4j.impl.StaticLoggerBinder
- Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
- Android 模拟机出现Installation failed due to invalid URI!错误
- PySe-016-Requests 访问 HTTPS 网站报错解决方法:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
- vsftp关于"550 create directory operation failed"问题解决
- SEVERE: One or more listeners failed to start.
- Git 常见错误 之 error: src refspec xxx does not match any / error: failed to push some refs to 简单解决方法
- MySQL workbench提示“Your connection attempt failed ...“解决方法
- 【安卓-疑难杂症】:你的主机中的软件中止了一个已建立的连接 and The application could not be installed: INSTALL_FAILED_USER_RESTRI