정리 필요


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;
            }
    
    
    CODE
  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
    CODE
  4. service 구동

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


문제 해결

다음 에러는 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";
CODE



잘못된 upstream 설정 예 - SCRIPT_FILENAME

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

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


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;
        }
CODE


같이 보기