WebSocket + Proxy request failed, returned 400

Source: Internet
Author: User

Scene

Business Services provide WebSocket services based on WebSocket to push report data, clients view reports on browsers, and pass requests to backend services via HTTP proxies.

Problem

When the client views the report data on the browser, the report function is abnormal, and the browser development tool views The WebSocket handshake on the service side and rejects it, returning to the bad request.

Analysis

4,001 is due to the client, so it should be a client request parameter or a path problem. By comparing the normal and abnormal websocket request messages, the abnormal messages are missing the HTTP header of Upgrade:websocket.
Upgrade belongs to the Hop-to-hop type of HTTP cache, unlike End-to-end, the latter in two client requests to the final backend service will not change, such as User-agent, while the former will be processed by proxy, the ability to use proxy Class Hop-to-hop header processing.

Solution Solutions

Nginx has the following solution, in the HTTP request head to fill up the Upgrade, provided that the agent to the back end of the message before the Upgrade.

map $http_upgrade $connection_upgrade {default upgrade;'' close;}proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection $connection_upgrade;
Reference

About Nginx+websocket 400 issues HTTPS://WWW.JIANSHU.COM/P/D5B136A27BDF
End-to-end and Hop-by-hop Headers https://tools.ietf.org/html/rfc2616#section-13.5.1

WebSocket + Proxy request failed, returned 400

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.