P
P
Pavel Kononenko2015-05-29 22:16:24
Nginx
Pavel Kononenko, 2015-05-29 22:16:24

Faye proxying through nginx. How is it done correctly?

Hello.
I'm trying to configure websocket proxying through Nginx. I do as it is written in the official documentation:

location /faye {
    proxy_pass http://127.0.0.1:9292;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

The connection is being created. In chrome, in the websockets section, you can see:
Status 101.
Switching protocols

However, no messages are received from the server via this channel. There is this error in nginx.error.log:
2015/05/29 13:46:38 [info] 27188#0: *32 client closed keepalive connection

What am I doing wrong?
Full config:
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

upstream faye_backend {
    server 127.0.0.1:9292;
}

server {
  listen 80 default_server deferred;
  listen [::]:80 default_server ipv6only=on;
  access_log /home/deploy/agrofor/current/log/nginx.access.log;
  error_log /home/deploy/agrofor/current/log/nginx.error.log info;

  server_name mydomain.com;
  passenger_enabled on;
  rails_env    production;
  root         /home/deploy/agrofor/current/public;

  # redirect server error pages to the static page /50x.html
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
      root   html;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location /faye {

    proxy_pass http://faye_backend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-05-29
@dizballanze

I use the following configuration for node.js faye server:

location /faye {
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://127.0.0.1:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        break;
    }

everything is working. Also check that your mount is exactly /faye.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question