nginxでリバースプロキシ使ってnode.jsのSocket.IOを使う
nginxの比較的新しいバージョンではWebSocketのリバースプロキシに対応しているので、試して見ました。
今回はsocket.ioを使い、
nginxのバージョンは1.4.3を使いました。
nginxのプロキシの設定を設定ファイルに加えます。
/etc/nginx/conf.d/default.conf
location /socket.io/ { proxy_pass <socket.ioのサーバ>; # 例) proxy_pass http://localhost:1234; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
設定を変えたら。
チェックをします。
$ sudo /etc/init.d/nginx configtest nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
問題がなければnginxの再起動
$ sudo /etc/init.d/nginx restart nginx を停止中: [ OK ] nginx を起動中: [ OK ]