動かざることバグの如し

近づきたいよ 君の理想に

Node.jsをインストールしてNginxと連携できるところまで

Node.jsをインストール

Nodebrewを使ってNode.jsを管理する

curl -L git.io/nodebrew | perl - setup

.bashrcの末尾に以下の一行を追記

export PATH=$HOME/.nodebrew/current/bin:$PATH
export NODE_PATH=$HOME/.nodebrew/current/lib/node_modules

source ~/.bashrcすればnodebrewコマンドが叩けるようになっているはず

Node.jsの最新版をインストール

nodebrew install-binary latest
nodebrew use latest

Node.jsでHello World

一応動作確認 適当にhello.jsでも作って

var http = require('http');

var server = http.createServer(function(req, res) {
  res.end("Hello World");
});

server.listen(3000);

node hello.jsを実行した状態でhttp://example.com:3000/を開くと表示されるはず

Expressをインストール

npm install -g express express-generator

Nginxをリバースプロキシとして利用

/etc/nginx/sites-available/defaultに以下を追記 ディレクトリ配置等はお好みで

server {
        listen 80;
        server_name node.nyaaz.info;

        index index.html;

        location / {
           root /usr/share/nginx/html/node;
                proxy_pass http://127.0.0.1:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }
}