배포

2023년 기준으로 ubuntu 20.04 에서 배포중입니다.

시스템 설정

단계별 설치

sudo apt update

# install node.js
sudo apt -y install nodejs

# isntall npm
sudo apt -y install npm

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

# shell apply
source ~/.bashrc

# node.js install 16.16.0
nvm install v16.16.0

# pm2 install
npm install pm2 -g

# yarn install
npm install -g yarn

# pm2 log rotate
pm2 install pm2-logrotate

한번에 설치 (option)

# one line install
sudo apt update && sudo apt -y install nodejs && sudo apt -y install npm && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash && source ~/.bashrc && nvm install v16.16.0 && npm install pm2 -g && npm install -g yarn && pm2 install pm2-logrotate

데이터베이스 (MySQL)

취향에 맞게 버전을 설치해주십시오.
권장하는 버전은 MySQL 8 입니다.

Nginx

Nginx 설치

sudo apt-get -y install nginx

# option
sudo apt install libnginx-mod-http-geoip

클라우드 플레어 포워드 설정 (option)

/etc/nginx/conf.d/cloudeflre.conf

set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2c0f:f248::/32;
set_real_ip_from 2a06:98c0::/29;

#use any of the following two

#real_ip_header CF-Connecting-IP;
real_ip_header X-Forwarded-For;

geoip 설정 (option)

/etc/nginx/geoip.conf

# GeoIP database path
geoip_country /usr/share/GeoIP/GeoIPv6.dat;

# country whitelist examplu
map $geoip_country_code $allowed_country {
    default yes;
}

install certbot (let’s encrypt ssl/tls certification) (option)

sudo apt install certbot python3-certbot-nginx

서버 설정

/etc/nginx/sites-available/service

server {
    server_name  domain.com www.domain.com;

    # location = /robots.txt { return 200 "User-agent: *\nDisallow: /\n"; }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Ip-Country $geoip_country_code;
    }

    location /api {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://localhost:9001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Ip-Country $geoip_country_code;
    }

   location /api/swagger-ui-init.js {
        allow 220.89.232.45;
        deny all;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://localhost:9001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

   location /api/swagger-ui-standalone-preset.js {
        allow 220.89.232.45;
        deny all;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://localhost:9001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location /api/swagger-ui-bundle.js {
        allow 220.89.232.45;
        deny all;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://localhost:9001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    
    # 이미지 서버
    location /images {
        alias  /home/ubuntu/project/chihiro-admin/backend/upload/;
        autoindex off;
    }
}
  • server_name을 변경해서 도메인을 매핑해주십시오.

  • allow 아이피를 변경하여 swagger 접속을 차단해주십시오.

서비스 활성화

sudo ln -s /etc/nginx/sites-available/service /etc/nginx/sites-enabled/service 

서비스 적용

sudo service nginx restart

프로젝트 배포

프로젝트 구축

cd ~
mkdir project
cd project
git clone https://github.com/chihiro888/chihiro-admin

백엔드 배포

cd backend
bash deploy_prod.bash

프론트엔드 배포

cd frontend
bash deploy_prod.

Last updated