Nginx + (nodejs, socketio, express) + php site

I am working on a full version of js, HTML5 canvas and want it to be "real time". Based on my research, I found out that node.js is an exciting perspective, so I configured it on my ubuntu 12 web server using socket.io, express, etc.

I am a programmer, but just a rookie in the world of web servers, so I ask you for help. I got confused in the general model of the system and want to clarify how it works. I may have read too many articles in a short time.

First of all: I am running nginx 1.2.x on my web server. As I know, nginx handles rquests, it is dedicated to port 80 (for me) and serves HTTP requests (also using php-fpm to serve php). Again, I have a successfully launched nodejs server on port 8080. I want to connect via websocket (due to its nature and protocol), since nginx does not support websocket, but I am confused about what is happening.

If I go to http // mydomain.tld: 8080, will this go through the node server and save nginx? In this case, the connection can be made through websocket and not be discarded on xhr or anything else (I do not want it because of scalability), right?

Then what should I do to have the same effect in http // mydomain.tld / game /? Just a proxy request in nginx.conf to the node server? How:

 # if a file does not exist in the specified root and nothing else is definded, we want to serve the request via node.js
try_files   $uri    @nodejs;          

location @nodejs
{       
     proxy_pass  127.0.0.1:8080;
     break;
}

: qaru.site/questions/484835/...

-, nginx? , , php- socket.io. , 80 websocket. ?

http://www.exratione.com/2012/07/proxying-websocket-traffic-for-nodejs-the-present-state-of-play/ , HAProxy nginx 1.3, ?

, , . , | | | .

PS: .

Ps2: : red5 (- java) + flash, .

+5
1

, nginx.

nginx nginx_tcp_proxy_module.

: http tcp. , webroot, - node.js( .io js ofc) .php php_fpm.

, nginx:

user  www-data;
worker_processes  16;

events {
    worker_connections  1024;
}

http {
    upstream node-js-myapp {
        server 127.0.0.1:3000;
    }

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
    gzip  on;

    server {
        listen          80;
        server_name    domain.xx;  # Multiple hostnames seperated by spaces
        root            /var/www/domain.xx; # Replace this
        charset         utf-8;
        access_log  /var/log/nginx/domain.xx.access.log  combined;
        error_log   /var/log/nginx/domain.xx.error.log;

        location ~ \.php$ {
                fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; 
                include /etc/nginx/conf.d/php_fpm; # Includes config for PHP-FPM (see below)
        }


        location / {
            index  index.html index.htm;
        }


        location ^~ /socket.io/ {
            try_files $uri @node-js-myapp;
        }

        location /status {
            check_status;
        }

        location @node-js-myapp { 
          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_pass  http://node-js-myapp;
        }
    }
}

tcp {
  upstream websocket-myapp {
    server 127.0.0.1:8080;
    check interval=3000 rise=2 fall=5 timeout=1000;
  }

  server {
    listen 3000;
    server_name _;
    access_log  /var/log/nginx/domain.xx.access.log;

    proxy_read_timeout 200000;
    proxy_send_timeout 200000;
    proxy_pass websocket-myapp;
  }
}

node.js:

var app = require('express').createServer()
var io = require('socket.io').listen(app);
io.set('transports', [
    'websocket'
  , 'flashsocket'
  , 'htmlfile'
  , 'xhr-polling'
  , 'jsonp-polling'
  ]);

app.listen(8080);

HEAD:

<script src="/socket.io/socket.io.js"></script>

, nginx ..., .

+6

All Articles