CentOS 8에서 Nginx와 함께 Sails.js 프레임워크 설치
이 페이지에서
- 전제 조건
- Node.js 설치
- Sails.js 설치
- Sails.js 애플리케이션 시작\n
- Sails.js용 시스템 서비스 파일 만들기
- Nginx를 Sails 애플리케이션의 역방향 프록시로 구성\n
- 방화벽 구성\n
- Sails.js 웹 인터페이스에 액세스
- 결론
Sails.js는 Node.js용 Javascript 프레임워크입니다. 실시간 응용 프로그램을 매우 빠르게 개발하는 데 사용됩니다. 이를 통해 Ruby on Rails와 같은 프레임워크의 MVC 아키텍처와 유사할 수 있습니다. 코드를 작성하지 않고도 앱 백엔드를 빠르게 시작하는 데 도움이 되는 청사진이 함께 제공됩니다. Angular, React, iOS, Android, Windows Phone, 맞춤형 하드웨어 또는 완전히 다른 것을 포함한 다른 프런트 엔드와 호환됩니다.
이 게시물에서는 CentOS 8에서 Nginx로 Sails.js를 설치하는 방법을 보여줍니다.
전제 조건
- CentOS 8을 실행하는 서버.\n
- 루트 암호는 서버에서 구성됩니다.\n
Node.js 설치
먼저 다음 명령을 사용하여 필요한 모든 종속 항목을 설치합니다.
dnf install curl gcc-c++ make -y
모든 종속성이 설치되면 다음 명령을 사용하여 노드 소스 리포지토리를 추가합니다.
curl -sL https://rpm.nodesource.com/setup_16.x | bash -
Node 소스 리포지토리를 추가한 후 다음 명령을 사용하여 Node.js를 설치합니다.
dnf install nodejs -y
설치가 완료되면 다음 명령을 사용하여 Node.js 버전을 확인합니다.
node --version
다음 출력이 표시되어야 합니다.
v16.4.0
Sails.js 설치
아래와 같이 NPM 명령을 사용하여 Sails.js를 설치할 수 있습니다.
npm -g install sails
다음으로 다음 명령과 함께 Sails.js를 사용하여 프로젝트를 만듭니다.
sails new myproject
애플리케이션 템플릿을 선택하라는 메시지가 표시됩니다.
Choose a template for your new Sails app: 1. Web App · Extensible project with auth, login, & password recovery 2. Empty · An empty Sails app, yours to configure (type "?" for help, or <CTRL+C> to cancel) ? 2
2를 입력하고 Enter 키를 눌러 애플리케이션을 설치합니다. 다음 출력이 표시되어야 합니다.
info: Installing dependencies... Press CTRL+C to cancel. (to skip this step in the future, use --fast) info: Created a new Sails app `myproject`!
Sails.js 애플리케이션 시작
다음으로 디렉터리를 myproject로 변경하고 다음 명령을 사용하여 애플리케이션을 시작합니다.
cd myproject
sails lift
다음 출력이 표시되어야 합니다.
info: Starting app... info: info: .-..-. info: info: Sails <| .-..-. info: v1.4.3 |\ info: /|.\ info: / || \ info: ,' |' \ info: .-'.-==|/_--' info: `--'-------' info: __---___--___---___--___---___--___ info: ____---___--___---___--___---___--___-__ info: info: Server lifted in `/root/myproject` info: To shut down Sails, press+ C at any time. info: Read more at https://sailsjs.com/support. debug: ------------------------------------------------------- debug: :: Thu Jun 24 2021 04:46:13 GMT-0400 (Eastern Daylight Time) debug: Environment : development debug: Port : 1337 debug: -------------------------------------------------------
CTRL + C를 눌러 응용 프로그램을 중지합니다.
Sails.js에 대한 Systemd 서비스 파일 생성
다음으로 애플리케이션을 관리하기 위해 systemd 서비스 파일을 생성해야 합니다.
다음 명령으로 만들 수 있습니다.
nano /lib/systemd/system/sails.service
다음 줄을 추가합니다.
[Unit] After=network.target [Service] Type=simple User=root WorkingDirectory=/root/myproject ExecStart=/usr/bin/sails lift Restart=on-failure [Install] WantedBy=multi-user.target
파일을 저장하고 닫은 후 다음 명령을 사용하여 systemd 데몬을 다시 로드합니다.
systemctl daemon-reload
다음으로 Sails 서비스를 시작하고 시스템 재부팅 시 시작되도록 활성화합니다.
systemctl start sails
systemctl enable sails
다음 명령을 사용하여 Sails의 상태를 확인할 수 있습니다.
systemctl status sails
다음 출력이 표시되어야 합니다.
? sails.service Loaded: loaded (/usr/lib/systemd/system/sails.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2021-06-24 04:47:07 EDT; 5s ago Main PID: 47388 (node) Tasks: 22 (limit: 25014) Memory: 148.1M CGroup: /system.slice/sails.service ??47388 node /usr/bin/sails lift ??47395 grunt Jun 24 04:47:09 centos8 sails[47388]: info: ____---___--___---___--___---___--___-__ Jun 24 04:47:09 centos8 sails[47388]: info: Jun 24 04:47:09 centos8 sails[47388]: info: Server lifted in `/root/myproject` Jun 24 04:47:09 centos8 sails[47388]: info: To shut down Sails, press+ C at any time. Jun 24 04:47:09 centos8 sails[47388]: info: Read more at https://sailsjs.com/support. Jun 24 04:47:09 centos8 sails[47388]: debug: ------------------------------------------------------- Jun 24 04:47:09 centos8 sails[47388]: debug: :: Thu Jun 24 2021 04:47:09 GMT-0400 (Eastern Daylight Time) Jun 24 04:47:09 centos8 sails[47388]: debug: Environment : development Jun 24 04:47:09 centos8 sails[47388]: debug: Port : 1337 Jun 24 04:47:09 centos8 sails[47388]: debug: -------------------------------------------------------
이 시점에서 Sails가 시작되고 포트 1337에서 수신 대기합니다.
Nginx를 Sails 애플리케이션의 역방향 프록시로 구성
Sails 애플리케이션에 대한 리버스 프록시로 Nginx를 설치하고 구성하는 것이 좋습니다.
먼저 다음 명령을 사용하여 Nginx 패키지를 설치합니다.
dnf install nginx -y
Nginx를 설치한 후 Sails용 Nginx 가상 호스트 구성 파일을 만듭니다.
nano /etc/nginx/conf.d/sails.conf
다음 줄을 추가합니다.
server { listen 80; server_name sails.domain.com; location / { proxy_pass http://localhost:1337/; proxy_set_header Host $host; proxy_buffering off; } }
완료되면 파일을 저장하고 닫습니다.
다음으로 다음 명령을 사용하여 구성 오류에 대해 Nginx를 확인합니다.
nginx -t
다음 출력이 표시되어야 합니다.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
다음으로 Nginx 서비스를 시작하고 시스템 재부팅 시 시작되도록 활성화합니다.
systemctl start nginx
systemctl enable nginx
이제 다음 명령을 사용하여 Nginx 서비스의 상태를 확인합니다.
systemctl status nginx
방화벽 구성
다음으로 방화벽을 통해 포트 80을 허용해야 합니다. 다음 명령으로 허용할 수 있습니다.
firewall-cmd --permanent --zone=public --add-port=80/tcp
다음으로 방화벽을 다시 로드하여 변경 사항을 적용합니다.
firewall-cmd --reload
완료되면 다음 단계로 진행할 수 있습니다.
Sails.js 웹 인터페이스에 액세스
이제 웹 브라우저를 열고 URL http://salis.domain.com을 사용하여 Sails.js 웹 인터페이스에 액세스합니다. 다음 화면에 Sails.js 기본 페이지가 표시되어야 합니다.

결론
축하합니다! CentOS 8에서 리버스 프록시로 Nginx와 함께 Sails.js를 성공적으로 설치했습니다. 이제 Sails로 실시간 애플리케이션 개발을 시작할 수 있습니다.