본문 바로가기
  • [성공하는 개발자] - Developer
PHP

[PHP] Nginx 설치

by Sein-JH 2021. 9. 30.
728x90

nginx 설치

RHEL/CentOS 에 nginx 설치 참고

php fpm 설치

  1. php-fpm 설치(php fpm 설치 및 설정 참고)
  2. nginx.conf
location ~ \.php$ {
            root           html;
            #fastcgi_pass   127.0.0.1:9000;
            fastcgi_pass   unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

 

 

 3. /etc/php-fpm.d/www.conf 

  ;listen = 127.0.0.1:9000
  listen = '/var/run/php5-fpm.sock'

  listen.owner = nginx
  listen.group = nginx
  listen.mode = 0660

  user = nginx
  group = nginx

 

4. service 구동

  chkconfig php-fpm on
  chkconfig nginx on
  service php-fpm restart
  service nginx restart

 

문제 해결

다음 에러는 upstream 설정이 잘못되어 있을 경우 발생

 

[error] 2402#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 210.181.192.103, server: localhost, request: "GET /i.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: 

없는 폴더를 root 로 지정

root 로 지정된 public 의 상위 폴더인 awesome-prj 폴더가 없을 경우 위 에러 발생

 

root "/var/www/myapp/awesome-prj/public";

 

잘못된 upstream 설정 예 - SCRIPT_FILENAME

php 소스 경로가 /scripts 로 설정되어 있어서 $document_root 로 변경하여 해결

#fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

 

location 내 잘못된 root

"Unable to open primary script: /usr/share/nginx/html/a.php (No such file or directory)"

 

server {
        listen       80;
        server_name  myhost;
        root         /var/www/laravel/public;
        
        location ~ \.php$ {
        ## 아래 구문에서 root 를 덮어써서 발생    
        #    root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

 

 

'PHP' 카테고리의 다른 글

[PHP]유튜브 자동 무한 제생  (0) 2021.12.09
[PHP] CodeIgniter 언어 클래스 - 다국어  (0) 2021.09.30
[PHP] Multi-Language setup in CodeIgniter  (0) 2021.09.30
[PHP] Mailer로 메일 전송  (0) 2021.09.30
[PHP] alert 창 띄우기  (0) 2021.09.29

댓글