#nvm 설치 참고: https://github.com/creationix/nvm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
#설치 후 다음 스크립트 실행
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
#node 설치
nvm install node
nvm use node
#nginx 설치 참고: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04
sudo apt-get update
sudo apt-get install nginx
#nginx 설정 sudo vi /etc/nginx/sites-available/default (환경에 따라 설정 파일은 다른 곳에 있을 수 있음)
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
#node 서버 실행 nginx 설정 파일에 있는 root 위치에서 다음과 같은 파일을 생성 app.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080);
console.log('Server running at http://APP_PRIVATE_IP_ADDRESS:8080/');
node app.js
##nginx 재실행 후 접속
sudo service nginx restart