nginx 설치 후 아래와 같이 php-fpm과 connection 실패가 되는 현상이 발생

2018/12/26 11:31:07 [error] 28434#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 222.235.208.2, server: hjshunas.iptime.org, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: ""



한참을 헤매다 centos 7 설치 후 selinux 설정되어 있는 것을 확인


selinux와 iptables rule 날리고 정상 connection 되는 것 확인



아래는 selinux 해제 방법과 iptables flush 방법 ( 보안이 필요한 환경에서는 권장하지 않고 php-fpm port 에 대해 whitelist 등록줘야 함 )



# 0이 selinux 해제 1이 설정
sudo setenforce 0

# 재기동 시에도 반영하기 위해 아래 파일 수정
sudo vi /etc/sysconfig/selinux

#SELINUX=enforcing
SELINUX=disabled

# iptables flush 후 저장
sudo iptables --flush
sudo service iptables save


'WEB개발 > nginx' 카테고리의 다른 글

nginx compile 설치 방법 ( CentOS )  (0) 2019.01.04
nginx를 위한 php-fpm 설치 방법 ( CentOS )  (1) 2019.01.04

[ nginx 1.12.2 설치 ] 

•1.12.2 버전 설치 (app 계정에서 설치) 

•라이브러리 Dependency : 기본적으로 pcre, zlib 라이브러리가 설치되어 있어야 함 

•해당 라이브러리가 설치되지 않을 경우 pcre, zlib 소스 디렉터리를 준비하고 아래 옵션을 configure 명령에 추가

•--with-pcre=/home/app/pkg/pcre-8.4.1 —with-zlib=/home/app/pkg/zlib-1.2.11

•해당 옵션을 활용하면 nginx 설치하면서 해당 라이브러리들을 자동으로 컴파일해서 설치하기 때문에 별도 설치할 필요 없음.


  • nginx 다운로드 후 압축을 푼다. ( 필요에 따라 pcre, zlib도 다운로드 )
mkdir pkg
cd pkg

# nginx 다운로드
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xvf nginx-1.12.2.tar.gz

# pcre 8.41 버전 다운로드
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
tar xvf pcre-8.41.tar.gz

# zlib 1.2.11 다운로드
wget http://zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz

  • 아래와 같이 nginx 소스 디렉토리 이동 후 configure 명령어 수행 ( prefix 및 path는 각자의 환경에 맞게 수정 필요 )
cd /home/app/pkg/nginx-1.12.2

./configure --prefix=/home/app/HOME/nginx --sbin-path=/home/app/HOME/bin/nginx --conf-path=/home/app/HOME/data/nginx/nginx.conf --error-log-path=/home/app/HOME/log/nginx/error.log --pid-path=/home/app/HOME/data/nginx/nginx.pid --with-http_ssl_module  --with-http_realip_module --with-http_stub_status_module --with-http_v2_module --with-pcre=/home/app/pkg/pcre-8.4.1

# pcre, zlib 라이브러리 같이 compile할 경우 아래 옵션 추가
# --with-pcre=/home/app/pkg/pcre-8.4.1 --with-zlib=/home/app/pkg/zlib-1.2.11

make
make install


[ nginx 연동 설정 ]

  • ~/HOME/data/nginx/nginx.conf 파일에서 아래 내용 확인

server { listen 9090; // Web에서 사용할 port 정보 명시 server_name 192.168.0.1; // Web ip 정보 명시 location / { root html; // 삭제 index index.html index.htm index.php; // index.php 항목 추가 } /* test 디렉터리 항목 전체 추가 */ location /test { index index.html index.php; try_files $uri $uri/ /test/index.php; } /* php-fpm 연동 정보 전체 추가 (기본적으로 주석 처리되어 있으며 내용이 일부 다름) */ # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }


[ nginx 기동 ]

# 기동
/home/app/HOME/bin/nginx

# 중지
/home/app/HOME/bin/nginx -s stop

# 설정 파일 리로드
/home/app/HOME/bin/nginx -s reload

# 아래는 nginx 도움말
hjshuweb [app{1006} ~/HOME/bin ] ./nginx -h
nginx version: nginx/1.12.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /home/app/HOME/nginx/)
  -c filename   : set configuration file (default: /home/app/HOME/data/nginx/nginx.conf)
  -g directives : set global directives out of configuration file

[ nginx 기동 확인 ]

http://{ip}:{port} 접속 후 nginx 초기 페이지 로딩 확인




1. WebTatic 저장소 설치
#CentOS 6
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

#CentOS 7
rpm -Uvh http://mirror.premi.st/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2. yum 으로 패키지 설치
yum install php56w-cli php56w-fpm php56w-mbstring php56w-mcrypt php56w-mysql php56w-opcache php56w-pdo php56w-pear php56w-xml

3. 부팅 시 php-fpm service 활성화
#CentOS 6
chkconfig php-fpm on

#CentOS 7
systemctl enable php-fpm.service

4. php-fpm 구동
#CentOS 6
service start php-fpm

#CentOS 7
systemctl start php-fpm.service

5. php-fpm 설정
vi /etc/php-fpm.d/www.conf

[root@hjshuweb php-fpm.d]# cat www.conf | grep -v ";"
[www]

listen = 127.0.0.1:9000

listen.allowed_clients = 127.0.0.1

listen.owner = app
listen.group = app
listen.mode = 0666

user = app

pm = dynamic

pm.max_children = 50

pm.start_servers = 5

pm.min_spare_servers = 5

pm.max_spare_servers = 35

slowlog = /var/log/php-fpm/www-slow.log

chdir = /home/app/HOME/nginx/html/

catch_workers_output = yes

php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on

php_value[session.save_handler] = files
php_value[session.save_path]    = /var/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache


'WEB개발 > nginx' 카테고리의 다른 글

nginx와 php-fpm간 connection 실패 시 조치 방법  (0) 2019.01.04
nginx compile 설치 방법 ( CentOS )  (0) 2019.01.04

+ Recent posts