10
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EC2にnodejsの環境を構築した時のメモ

Posted at

sshで対象のインスタンスにログイン

yumをupdate

$ sudo yum update

yumから必要なパッケージをインストール

$ sudo yum install git gcc-c++ make openssl-devel

nginxを入れる

$ sudo yum install nginx -y

nginxを起動する

$  sudo chkconfig nginx on
$  sudo service nginx start

nginx.confに設定を追加

location / {
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_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3000/;
proxy_redirect off;
}

nvmをいれる

$ git clone git://github.com/creationix/nvm.git .nvm

~/.bash_profileに設定を追加

if [[ -s ~/.nvm/nvm.sh ]];
 then source ~/.nvm/nvm.sh
fi
$ source ~/.nvm/nvm.sh

インストール可能なnode.jsのバージョンの一覧を表示

$ nvm ls-remote

nvmからnode.jsをインストール

$ nvm install [任意のversion]

入れたnodeのversionを確認

$ node -v

nvmのデフォルトバージョンを定義

$ nvm alias default [installした任意のversion]

express generatorをいれる

$ sudo npm install express-generator -g

expressアプリケーションを作成

$express Testapp

アプリケーションフォルダに移動

$cd Testapp

npmパーケージをインストール

$sudo npm install

expressを起動

$ node ./bin/www

NodeENVを入れる

~/.bash_profileに設定を追加
NODE_ENV=rice
export NODE_ENV

これでnodejsをNginx上で動くことが確認できた

10
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?