nginx 1.16.1 에서 php-fpm 연동시 default.conf 파일 추가 설정 > 질문답변

본문 바로가기
사이트 내 전체검색

질문답변

nginx 1.16.1 에서 php-fpm 연동시 default.conf 파일 추가 설정

페이지 정보

profile_image
작성자 미친새
댓글 0건 조회 25,129회 작성일 20-02-28 16:36

본문

version 정보
nginx : 1.14.0
php : 7.1.18
yum install nginx 를 통해서 설치하였으며,

# yum install nginx
[root@centos html]# nginx -v
nginx version: nginx/1.14.0

php71 은 remi repo를 추가해서 아래와 같이 설치했다.

# yum --enablerep=remi-php71 install php-fpm php-common
[root@centos html]# php -v
PHP 7.1.18 (cli) (built: May 24 2018 07:59:58) ( NTS )
Copyright © 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright © 1998-2018 Zend Technologies

설정파일

/etc/php-fpm.d/www.conf 파일

########### file /etc/php-fpm.d/www.conf
user = nginx
group = nginx
;listen은 nginx 설정과 맞춰줘야 한다.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock;
listen.owner = nginx
listen.group = nginx
/etc/nginx/conf.d/default.conf 파일

########### file /etc/nginx/conf.d/default.conf

server {
    listen  80;
    server_name  your_server_ip;

    # note that these lines are originally from the "location /" block
    # root 설정이 없으면 404 에러가 날수 있다.
    root  /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        #fastcgi_pass 는 아래 두개 중 아무거나 사용해도 좋으나 php-fpm.d/www.conf 설정과 맞춰줘야 한다.
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        #/scripts 이름으로 인해서 오류가 생길 수 있다.
    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
에러상황 #1
사이트에 접속은 되는데 404 error 또는 파일을 찾을 수 없는 상황

[error] 7469#7469: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.0.114, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:",
해결방법

/etc/nginx/conf.d/default.conf 설정파일에서 아래와 같이 root 폴더 설정을 한다.

server {
root /usr/share/nginx/html;
index
}
에러상황 #2
*1 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (13: Permission denied) while connecting to upstream,
php-fpm.sock 의 그룹:사용자 권한 문제
아래와 같은 명령어로 해결할 수 있다.

# chown nginx:nginx /var/run/php-fpm/php-fpm.sock
다른 분들 고생 안했으면 좋겠다.

도움사이트 : https://www.hostinger.com/tutorials/how-to-install-lemp-centos7





server{} 안에다가 넣는다. 맨 마지막줄에

location ~ \.php$ {
try_files $uri =404;
#fastcgi_pass 는 아래 두개 중 아무거나 사용해도 좋으나 php-fpm.d/www.conf 설정과 맞춰줘야 한다.
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
#/scripts 이름으로 인해서 오류가 생길 수 있다.
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
출처: https://forteleaf.tistory.com/entry/nginx-php71-phpfpm-설치하기 [부들잎의 이것저것]

첨부파일

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

회사명 : 회사명 / 대표 : 대표자명
주소 : OO도 OO시 OO구 OO동 123-45
사업자 등록번호 : 123-45-67890
전화 : 02-123-4567 팩스 : 02-123-4568
통신판매업신고번호 : 제 OO구 - 123호
개인정보관리책임자 : 정보책임자명

공지사항

  • 게시물이 없습니다.

접속자집계

오늘
1,982
어제
2,368
최대
3,834
전체
847,435
Copyright © 소유하신 도메인. All rights reserved.