nginx reverse proxy websockets

前端 未结 1 1573
无人共我
无人共我 2021-02-01 17:46

nginx now supports proxying websockets, but I was unable to find any information on how to do this without having a separate location block that applies to URIs on whic

相关标签:
1条回答
  • 2021-02-01 18:28

    Why doesn't nginx just forward the original Upgrade/Connection headers?

    From the official documentation: since the “Upgrade” is a hop-by-hop header, it is not passed from a client to proxied server

    See RFC 2616.


    I don't want the Upgrade header or Connection being set to "upgrade" unless that's what the browser sent,

    There is also an example:

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
    
    server {
        ...
    
        location /chat/ {
            proxy_pass http://backend;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }
    

    Connection is 'upgrade' for non-websocket requests, which is also bad.

    Do you actually know what the Connection header means? Just a quote from RFC: for each connection-token in this field, remove any header field(s) from the message with the same name as the connection-token.

    How it can be bad?

    0 讨论(0)
提交回复
热议问题