Generally, it is no problem to set up a proxy by pressing it down. However, we are going to operate websockt today

 server {
    location / {
        proxy_ pass http://127.0.0.1:10086;
        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 REMOTE-HOST $remote_ addr;
        proxy_ http_ version 1.1;
        proxy_ read_ timeout 300s;
    }
}

nginx -t once

The following error occurs:
nginx: [emerg] unknown "connection_ upgrade" variable

It's here that there's a hole

It involves the design of nginx End-to-end and Hop-by-hop Headers
I'm not going to repeat it here, so as not to mislead people

Map in nginx is to set up a mapping table for one or more variables

Here are some configurations to add:

 http {
    map $http_ upgrade $connection_ upgrade {
        default upgrade;
        ''      close;
    }

    server {
        location / {
            #… 
            proxy_ set_ header Upgrade $http_ upgrade;
            proxy_ set_ header Connection $connection_ upgrade;
        }
    }
}

label: nginx , websocket

There have been three comments

  1. [...]} although the problem has been solved, I want to know why this happens and the real principle of the solution. In this blog, you can see that the problem lies in the nginx proxy websocket. What is websocket? The traditional HTTP communication mode is: the client initiates the request, and the server receives the request and responds. The websocket protocol reuses the handshake channel of HTTP. Specifically, the client negotiates the upgrade protocol with the websocket server through HTTP request. The first step is to establish a connection. The client uses HTTP message [...]

  2. Have you taught how to do VPN?

Add a new comment