2014-03-04 28 views
0

使用PHP-FPM nginx的從PHP-FPM 1-2分鐘「未指定輸入文件」,PHP-FPM重啓後一切正常OK,除了約1-2分鐘。在此期間,對於全部 .php網址返回「沒有指定輸入文件」。 1-2分鐘後,一切恢復正常,無需採取進一步行動。在/var/log/nginx/error.log後重啓

示例項:

2014/03/04 09:21:22 [error] 1206#0: *55 FastCGI sent in stderr: "Unable to open primary script: /usr/share/nginx/html (Success)", client: xxx.aaa.bbb.ccc, server: www.example.com, request: "GET /xxx/index.php HTTP/1.1", host: "www.example.com" 

下面是爲server.conf服務器塊:

server { 
    listen  443 ssl; 
    server_name www.example.com; 

    ssl_certificate  /etc/nginx/ssl-bundle.crt; 
    ssl_certificate_key /etc/nginx/cert.key; 

    ssl_session_cache shared:SSL:1m; 
    ssl_session_timeout 5m; 

    ssl_ciphers HIGH:!aNULL:!MD5; 
    ssl_prefer_server_ciphers on; 

    root /usr/share/nginx/html; 
    index index.php index.html; 

    location/{ 
     try_files $uri $uri/ $uri/index.php; 
    } 

    location ~ \.php { 
     fastcgi_split_path_info ^(.+\.php)(.+)$; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
     fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
     fastcgi_pass php; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 

而且/etc/nginx/nginx.conf :

http { 
    ... 

    sendfile  on; 

    keepalive_timeout 65; 
    charset utf-8; 
    gzip on; 
    gzip_static on; 
    etag on; 
    upstream php { 
     server unix:/var/run/php5-fpm.sock; 
    } 
    open_file_cache max=1000 inactive=20s; 
    open_file_cache_valid 30s; 
    open_file_cache_min_uses 2; 
    open_file_cache_errors on; 
    keepalive_requests 100000; 
    expires max; 

    include /etc/nginx/conf.d/*.conf; 
} 

任何想法如何解決它?事實上,它只是在重啓php-fpm後的短暫時間內發生,似乎排除了一些常見問題(例如權限),並且看起來更像是緩存?謝謝!

+0

你如何重新啓動PHP-FPM,你可以發佈池的FPM配置? – Danack

+0

冒着嘗試的風險是隨機的,請將fastcgi_pass行更改爲「fastcgi_pass unix:/var/run/php5-fpm.sock;」 ? – Danack

+0

@Danack使用'/etc/rc.d/init.d/php-fpm restart'(CentOS)重新啓動。我已經在[link](http:// pastebin。)上放了一份'/ etc/php-fpm.d/www.conf'。COM/UcaBxngc)。 – tetech

回答

0

我想我已經解決了這個問題。有必要將/usr/share/nginx/html(或更一般地說,$document_root)添加到php.ini或nginx配置中的open_basedir路徑。這工作:

location ~ \.php { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    include fastcgi_params; 
    fastcgi_param PHP_VALUE "open_basedir=$document_root"; 
    fastcgi_param PATH_INFO $fastcgi_path_info; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_pass php; 
    fastcgi_index index.php; 
} 

註釋掉PHP_VALUE導致問題返回。我仍然不明白爲什麼問題發生或爲什麼這解決了它;無論是用php-fpm,APC,nginx還是其他的東西。

0

這真是不可思議。這可能不是這樣的答案,但是這裏太多的文字不適合在一個小評論框中。

1)錯誤肯定是從PHP-FPM來了,是不是一個緩存問題。錯誤消息來自:http://lxr.php.net/xref/PHP_5_5/sapi/fpm/fpm/fpm_main.c#1920,由於PHP無法打開腳本。

顯然zlog錯誤被寫入stderr PHP日誌 - 您已將其設置爲/var/log/php-fpm/www-error.log。那裏有什麼嗎?如果不是,你可能需要重新編譯PHP,或者調整你的日誌設置以找出錯誤。

2)運行PHP-FPM作爲nginx的用戶是一種奇怪的。 Nginx需要作爲一個特權進程來運行,因爲它監聽端口80,而PHP-FPM則不需要。我通常會爲每個網站創建一個用戶,然後爲每個網站在該用戶下運行PHP-FPM池。可能與您的問題無關 - 但誰知道。

3)沒有打開文件是真的很奇怪,我根本不理解它。您可能需要運行strace的要弄清楚什麼是真正發生的事情,就像這樣:

#!/bin/bash 

# Prevent strace from abbreviating arguments? 
# You want the -s strsize option, which specifies the maximum length of a string to display (the default is 32). 

rm -rf trc/*.trc 

additional_strace_args="$1" 

mkdir trc 

MASTER_PID=$(ps auwx | grep php-fpm | grep -v grep | grep 'master process' | cut -d ' ' -f 7) 



# ls -l /tmp/foobar | awk '{print $1"\t"$9}' 
# This code takes some input, such as this: 
# -rw-rw-rw- 1 root  root   1 Jul 14 1997 tmpmsg 
# and generates output like this: 
# -rw-rw-rw-  tmpmsg 




#shows total of calls 
summarise="" 
# summarise="-c" 


nohup strace -r $summarise -p $MASTER_PID -ff -o ./trc/master.follow.trc >"trc/master.$MASTER_PID.trc" 2>&1 & 

while read -r pid; 
do 
    if [[ $pid != $MASTER_PID ]]; then 

     #shows individual calls 
     #nohup strace -r -p "$pid" $additional_strace_args >"trc/$pid.trc" 2>&1 & 

     #shows total of calls 
     nohup strace -r $summarise -p "$pid" $additional_strace_args >"trc/$pid.summary.trc" 2>&1 & 
    fi 
done < <(pgrep php-fpm) 


read -p "Strace running - press [Enter] to stop" 

pkill strace 

順便說一句,我要繼續前進,並揣測你長時間運行的php-fpm的腳本。您正在使用的重啓命令正在進行平穩重啓。如果其中一個腳本需要很長時間,那可能會解釋您所看到的行爲。