Why is the nginx proxy_pass instruction http protocol when using nginx proxy wss?

Program I have tested through
the following is the configuration of nginx forwarding
I don"t understand

websocket service I opened a websocket service using gatewayworker

Why is http in forwarding

if I visit this address directly, he will prompt for an error

location /wss
{
    proxy_pass http://127.0.0.1:8585;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
}

what is the principle of this?


Nginx itself is a Server, when nginx runs as a proxy server, user An initiates a http request to nginx is actually a tcp/ip-based connection, because http is a composite protocol of the tcp/ip suite. When nginx receives the request, nginx traverses the array of location modules under the server instance and reads the module configuration after matching to the module. Proxy_pass parameter is the next hop target host of nginx, and a trusted transport-based connection needs to be established between the two hosts, while tcp/ip provides reliable connection (connection-oriented) and based on transmission . Therefore, it is the best choice to establish a reliable connection between the nginx server and the host based on tcp/ip. When nginx parses the url of the proxy_pass parameter, it seems reasonable to establish a reliable http-based connection with the host. The nginx agent has now opened the connection between both sides, so you can start transporting resources.


this video of the actual combat project between workerman and thinkPHP is good. It uses websocket protocol to achieve a long connection to do instant messaging and online customer service. Address http://study.163.com/course/i.

Menu