OS

2022.02.14 17:36

Nginx / php-fpm 소켓 연동

  • 비아웹 오래 전 2022.02.14 17:36 인기
  • 4,553
    0

1. 설치 환경

OS : CentOS Linux release 7.8.2003 (Core)

SELINUX : disabled

NGNIX - 1.18.0

PHP - 7.3.25 (fpm-fcgi)

 

2. Nginx 설치

 

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum -y install --enablerepo=nginx nginx

3. Nginx - default.conf 설정

[root@localhost ~]# cd /etc/nginx/conf.d
[root@localhost conf.d]# cp default.conf default.conf.ori
[root@localhost conf.d]# mv default.conf viaweb.co.kr.conf
-- vi /etc/nginx/conf.d/viaweb.co.kr.conf --
(원본)
server {
listen 80;<= 포트지정
server_name localhost;
 
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main; <= 로그설정
 
location /{
root /usr/share/nginx/html;<= 경로설정
index index.html index.htm;
}
--------------------------------------------
(수정)
server {
listen 80;
server_name localhost;
 
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
 
location /{
root /home/viaweb/public_html;
index index.php index.html index.htm;
}
 
-- vi /etc/nginx/conf.d/viaweb.co.kr.conf --
 
# nginx Configtest
[root@localhost ~]# nginx-t
 
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx

4. PHP-FPM 설치

[root@localhost ~]# yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[root@localhost ~]# yum -y install --enablerepo=remi,remi-php73 php php-fpm
[root@localhost ~]# systemctl enable php-fpm

5. PHP-FPM & Nginx 소켓 연동

[root@localhost ~]# vi /etc/php-fpm.d/www.conf.d
-- vi /etc/php-fpm.d/www.conf.d --
 
(수정 전)(수정 후)
24 user = apache <=> user =nginx
26 group = apache <=> group =nginx
38 listen =127.0.0.1:9000 <=> listen =/var/run/php-fpm/php-fpm.sock
48;listen.owner = nobody <=> listen.owner =nginx
49;listen.group = nobody <=> listen.group =nginx
50;listen.mode =0660 <=> listen.mode =0660
 
-- vi /etc/php-fpm.d/www.conf.d --
 
[root@localhost ~]# systemctl restart php-fpm
[root@localhost ~]# ls -l /var/run/php-fpm/
total 4
-rw-r--r--1 root root 4 Dec 232020 php-fpm.pid
srw-rw----1nginxnginx0 Dec 232020 php-fpm.sock
-- vi /etc/nginx/conf.d/viaweb.co.kr.conf --
 
(원본)
# location ~.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME/scripts$fastcgi_script_name;
# include fastcgi_params; #}
------------------------------------------------------------
 
(수정)
location ~.php$ {
root /home/viaweb/public_html;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME/home/viaweb/public_html$fastcgi_script_name;
include fastcgi_params;
 
-- vi /etc/nginx/conf.d/viaweb.co.kr.conf --
 
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# echo "<?php phpinfo(); ?>">/home/viaweb/public_html/phpinfo.php

6. 방화벽 포트 오픈

** iptables 사용 시
[root@viaweb ~]# iptables -IINPUT-p tcp --dport 80-j ACCEPT
 
** firewalld 사용 (--permanent 옵션 추가 시 영구적으로 등록)
[root@viaweb ~]# firewall-cmd --permanent --add-port=80/tcp
[root@viaweb ~]# firewall-cmd --reload

http://<IP주소>.phpinfo.php

감사합니다.

서버호스팅 비아웹

 
  • 공유링크 복사

    댓글목록

    등록된 댓글이 없습니다.