Proxying websocket (to e.g. tomcat)
    Valentin V. Bartenev 
    vbart at nginx.com
       
    Thu Feb 21 16:03:52 UTC 2013
    
    
  
On Thursday 21 February 2013 19:55:45 Nikolai Zhubr wrote:
> 21.02.2013 18:30, Valentin V. Bartenev wrote:
> [...]
> 
> > Yes, it's possible with 1.3.13. And yes, you need some additional
> > configuration.
> > 
> > Example:
> >      location /examples/websocket {
> >      
> >          proxy_pass  http://127.0.0.1:8080;
> >          proxy_http_version 1.1;
> >          proxy_set_header Upgrade $http_upgrade;
> >          proxy_set_header Connection "upgrade";
> >      
> >      }
> 
> Ah, this indeed helped! Now it works. Thank you very much.
> 
> Apparently such configuration implies that different kinds of
> connections (standard and websocket) can not be mixed in one "location"
> section? (As far as I understood it, magic headers do not get through
> directly, but essentially get reintroduced by these configuration
> settings?)
> 
Not quite so. Actually, they can be mixed. That's why the $http_upgrade variable 
used. If there's no such header in request, then the variable is empty and the 
header won't be set.
You can also set the Connection header to different values depending on 
existence of the Upagrade header in a request.
Example:
  http {
      map $http_upgrade $conn_header {
          default        upgrade;
          ''             close;
      }
      server {
          ...
          location {
              proxy_pass  http://127.0.0.1:8080;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection $conn_header;
          }
      }
http://nginx.org/r/map
  wbr, Valentin V. Bartenev
--
http://nginx.com/support.html
http://nginx.org/en/donation.html
    
    
More information about the nginx
mailing list