개발이야기

우분투 서버에 node.js + nginx 셋팅

Roslyn 2023. 4. 21. 15:24
반응형
1. 깨끗한 VM인 경우에 먼저 apt를 업데이트 해줍니다.

sudo apt update

 

2. Nodsjs 설치

sudo apt install nodejs

 

3. Nodejs 버전 업그레이드

(1) nvm 설치

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

(2) source ~/.bashrc
(3) nvm install 16.0.0

 

4. NPM 설치

sudo apt install npm

 

5. 환경설정

nano ~/.bashrc

수정화면이 열리면 맨 하단에 다음줄 추가

export PATH="$PATH:/usr/local/bin"

 

6. pm2 설치

sudo npm install -g pm2

 

7. nginx 설치

sudo apt install nginx

 

8. nginx 시작

sudo systemctl start nginx

 

9. nginx 설정파일 수정

/etc/nginx/sites-available 에 있는 default 를 다음 내용으로 수정

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:4000;
        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;
    }
}

 

10. nginx 재시작

sudo systemctl restart nginx

 

11. 재부팅 이후에 자동 시작 설정

sudo systemctl enable nginx

 

이후 프로젝트 파일을 업로드하려할 때 권한 이슈가 생긴다면, 해당 폴더에 권한설정을 하고 업로드하자.
sudo chmod 777 /var/www
반응형