Skip to content

Instantly share code, notes, and snippets.

@makkaba
Created January 18, 2017 16:32
Show Gist options
  • Save makkaba/bb296f9c2ae7b58a55fcc6641f5dd134 to your computer and use it in GitHub Desktop.
Save makkaba/bb296f9c2ae7b58a55fcc6641f5dd134 to your computer and use it in GitHub Desktop.
node.js 헬로월드
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080, 'localhost');
console.log('Server running at http://localhost:8080/');
@makkaba
Copy link
Author

makkaba commented Jan 18, 2017

이때의 nignx의 설정(sites-available)은 다음과 같다.

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;
    }
}

tutorial 참고
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

다른 블로그에서 본거

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://127.0.0.1:3000/;
      proxy_redirect off;
}

이거 또한 잘 됐다

@makkaba
Copy link
Author

makkaba commented Jan 18, 2017

추가로 hello_express.js는 이렇게 테스트하면 되겠다.

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello Express')
})

app.listen(8080, function () {
  console.log('Example app listening on port 8080!')
})

!아마존 ec2를 사용한다면 8080포트가 다 열려있어야 함!

@makkaba
Copy link
Author

makkaba commented Feb 20, 2017

pm2 실행 (production mode)

NODE_ENV=production pm2 start app.js

@makkaba
Copy link
Author

makkaba commented Mar 15, 2017

이렇게 해도 된다
config.yml

apps:
  - script : index.js
    watch  : true
    env    :
      NODE_ENV: production
    env_production:
      NODE_ENV: production

pm2 start config.yml

@makkaba
Copy link
Author

makkaba commented Mar 15, 2017

시스템 리부팅 시에도 pm2 프로세스가 작동되도록 하려면
pm2 startup 명령어를 마지막에 쳐줘야 함

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment