socket.io をリバースプロキシさせたかったので、Nginx 1.3.13をインストールしてみた。
$ wget http://nginx.org/download/nginx-1.3.13.tar.gz $ tar xf nginx-1.3.13.tar.gz $ aptitude install libpcre3-dev zlib1g-dev libssl-dev libxslt1-dev libgd2-xpm-dev libgeoip-dev $ cd nginx-1.3.13 $ ./configure \ --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-client-body-temp-path=/var/lib/nginx/body \ --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \ --http-log-path=/var/log/nginx/access.log \ --http-proxy-temp-path=/var/lib/nginx/proxy \ --http-scgi-temp-path=/var/lib/nginx/scgi \ --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \ --lock-path=/var/lock/nginx.lock \ --pid-path=/var/run/nginx.pid \ --with-pcre-jit \ --with-debug \ --with-http_addition_module \ --with-http_dav_module \ --with-http_geoip_module \ --with-http_gzip_static_module \ --with-http_image_filter_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-http_sub_module \ --with-http_xslt_module \ --with-ipv6 \ --with-sha1=/usr/include/openssl \ --with-md5=/usr/include/openssl \ --with-mail \ --with-mail_ssl_module $ make $ make install
設定ファイル
server { listen 80; ## listen for ipv4; this line is default and implied server_name hoge.com; location / { proxy_pass http://127.0.0.1:8000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }
サーバースクリプト
cluster = require 'cluster' config = require 'config' cpus = require('os').cpus() if cluster.isMaster cpus.forEach -> cluster.fork() else RedisStore = require 'socket.io/lib/stores/redis' io = require('socket.io').listen(8000) io.configure ()=> options = { host: config.redis.host, port: config.redis.port } store = new RedisStore redisPub: options, redisSub: options, redisClient: options io.set 'store', store io.sockets.on('connection', (socket)=> socket.emit('news', { hello: 'world' }) socket.on('my other event', (data)=> console.log(data) ) )