[리눅스 환경] How to install Node.js on a VPS or a Dedicated server (e.g. 김치하우스 캘거리)
아시는 분의 Portfolio 용 사이트를 공동 작업하는 과정에서, Apche 와 Node.js를 연동해야 하는 상황 발생
1. Node 와 npm 버전 확인
a) node --version : v12.19.0
b) npm --version : 6.14.8
2. Node.js apps 실행
- To run a Node.js application that is production-ready and has a package.json file included,
you can use the following command:
nohup npm start --production &
--> 여기서 nohup 명령어는 HUP 시그널을 무시시켜서 백그라운 프로세스 실행을 가능하게 한다고 한다.
- Node.js app 이 packag.json 파일을 포함하고 있지 않는 경우에는:
nohup node my_app.js &
3. Connect your Website with a Running Node.js App
- 김치하우스 웹사이트는 VPS에 호스팅되어 있는데, cPanel 이라는 web hosting control panel이 제공되고 있다.
cPanel 상에서 설정 파일을 수정하는 방법을 구글링 해서 찾아야 했다.
1) Go to File Manager --> public_html folder
2) Hidden file 볼 수 있게 설정 확인
- Setting buton on the upper-right
3) .htaccess file 수정 : replace XXXXX with the port your Node.js application is working on.
DirectoryIndex disabled
RewriteEngine On RewriteRule ^$ http://127.0.0.1:XXXXX/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:XXXXX/$1 [P,L]
4. How to stop an appplication
pkill node