Web/Nginx
Nginx에 Node.js 설치하기 ( fast-cgi ) for Centos7
Hannah_ko
2020. 10. 5. 09:41
SMALL
Centos 환경에서 nginx 엔진에 php-fpm을 설치한 후,
node.js를 설치하여 환경 설정을 셋팅해보는 방법을 알아보자.
php-fpm과 Node.js로 Fast-CGI 세팅하기
1. epel 저장소 확인
$ yum repolist | grep epel
* epel: d2lzkl7pfhq30w.cloudfront.net
!epel/x86_64 Extra Packages for Enterprise Linux 13,445+1
1-1. epel 저장소가 없으면 설치
$ yum install epel-release
2. Node.js 설치
$ yum -y install nodejs
3. 설치 확인
$ node -v
v12.18.4
$ npm -v
6.14.6
node.js 설치 시 npm도 같이 설치된다.
4. nginx conf 파일 수정하기
$ vi /etc/nginx/conf.d/default.conf
server {
listen 80;
listen [::]:80;
server_name 127.0.0.1;
root /var/www/html;
index info.php index.html index.htm index.php;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index info.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location 블록의 proxy_pass 부분을 node.js의 기본 포트인 3000포트로 바꿔준다.
(선택) 4. Express 설치하기
$ npm install express --save
LIST