2014-02-28 34 views
14

我收到錯誤消息:nginx的 - 無法打開主腳本

FastCGI sent in stderr: "Unable to open primary script: /home/messi/web/wordpress/index.php (No such file or directory)" while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: www.domain.com, request: "GET/HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.domain.com

here are my configuration files:

/etc/php5/fpm/php.ini

cgi.fix_pathinfo=0 
doc_root = 
user_dir = 
.... 

/etc/php5/fpm/php-fpm.conf

[global] 
pid = /var/run/php5-fpm.pid 
error_log = /var/log/php5-fpm.log 
include=/etc/php5/fpm/pool.d/*.conf 

/etc/php5/fpm/pool.d/www.conf

[www] 
user = www-data 
group = www-data 
listen = /var/run/php5-fpm.sock 
listen.owner = www-data 
listen.group = www-data 
listen.mode = 0666 
pm = dynamic 
pm.max_children = 5 
pm.start_servers = 2 
pm.min_spare_servers = 1 
pm.max_spare_servers = 3 
chdir =/
security.limit_extensions = .php .php3 .php4 .php5 
php_flag[display_errors] = on 
php_admin_value[error_log] = /var/log/fpm-php.www.log 
php_admin_flag[log_errors] = on 

/etc/nginx/nginx.conf

user nginx; 
worker_processes 1; 
error_log /var/log/nginx/error.log warn; 
pid  /var/run/nginx.pid; 
events { 
    worker_connections 1024; 
} 
http { 
    include  /etc/nginx/mime.types; 
    server_tokens off; 
    default_type application/octet-stream; 
    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 
    access_log /var/log/nginx/access.log main; 
    sendfile  on; 
    #tcp_nopush  on; 
    keepalive_timeout 65; 
    #gzip on; 
    include /etc/nginx/sites-enabled/*; 
} 

的/ etc/nginx/sites-enabled/wordpress

server { 
    listen 80; 
    server_name www.domain.com; 
    root /home/messi/web/wordpress; 
    error_log /var/log/nginx/err.wordpress.log; 
    index index.php; 
    location/{ 
     try_files $uri $uri/ /index.php?$args; 
    } 
    location = /favicon.ico { 
     log_not_found off; 
     access_log off; 
    } 
    location = /robots.txt { 
     allow all; 
     log_not_found off; 
     access_log off; 
    } 
    location ~ /\. { 
     deny all; 
    } 
    location ~* /(?:uploads|files)/.*\.php$ { 
     deny all; 
    } 
    location ~ \.php$ { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include /etc/nginx/fastcgi_params; 
    } 
} 

設置用戶權限:

#adduser www-data messi 
#chown -R www-data:www-data /home/messi/web 
#chmod -R 664 /home/messi/web/wordpress 

我怎樣才能解決這個問題? 謝謝

回答

4

這可能是一個權限問題。

  1. 確保每個父目錄對用戶(nginx用戶和/或php-fpm用戶)具有+ x權限。

    您可以通過以下方式檢查這些權限:namei -om /path/to/file

  2. 如果您有符號鏈接,請確保它們指向有效的路徑。

  3. 確保chroot可以訪問正確的路徑。

  4. 確保SELinux(例如Fedora/Centos)或AppArmor(例如Ubuntu)或任何其他MAC安全系統不會干擾文件訪問。

    SELinux的: 檢查/var/log/audit/audit.log或/ var/log/messages中

    AppArmor的: 我不是一個Ubuntu的用戶而據我瞭解AppArmor的心不是記錄總是很容易弄清楚。你可能在這裏獲得信息:http://ubuntuforums.org/showthread.php?t=1733231

+1

對於我從Ubuntu 12.04切換到14.04時發生問題。看起來像'/ home'裏的12.04用戶文件夾默認具有'755'('drwxr-xr-x')權限。而在14.04,他們擁有'700'權限('drwx ------')。因爲Web服務器在'www-data'用戶下運行,所以'www-data'用戶無法訪問'/ home/user1404/wordpress/index.php'下的wordpress目錄,因爲'user1404'具有'700'權限。 –

+0

如果你想爲CentOS 7禁用它,編輯'/ etc/selinux/config'設置爲 '「SELINUX = disabled」'然後重啓。 –

-2
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; -> 
fastcgi_param SCRIPT_FILENAME/home/messi/web/wordpress$fastcgi_script_name; 
+6

此答案位於低質量帖子評論隊列中,因爲它只是沒有解釋的代碼。請通過解釋您的代碼的作用以及它如何回答問題來改進您的答案。請閱讀[有關回答編程問題的建議](http://msmvps.com/blogs/jon_skeet/archive/2009/02/17/answering-technical-questions-helpfully.aspx)。 –

23

的SELinux會導致在CentOS/RHEL這個錯誤7+默認:(

要測試的SELinux是你的災難之源,做

setenforce 0 

...,看看是否一切正常。如果這能解決它,你可以離開了SELinux關閉(弱,你比這更好的),或者你可以用

打開它
setenforce 1 

...然後正確地解決問題。

如果你

tail -f /var/log/audit/audit.log 

...你會看到SELinux的問題。就我而言,它拒絕PHP-FPM訪問網頁文件。您可以運行下面的指令來解決它:

setsebool -P httpd_can_network_connect_db 1 
setsebool -P httpd_can_network_connect 1 

這實際上並沒有在第一次幫我,但隨後恢復的SELinux做了

restorecon -R -v /var/www 

希望有所幫助。

+1

經過一小時的掙扎之後,這就是我的幫助!謝謝! –

+1

在CentOS 7上完美工作 – almyz125

+1

在CentOS 6上也發生了同樣的情況,並且restorecon命令正常工作。 –

-1

OMG我花了一個小時試圖修復它並驗證SELinux環境剛剛救了我的命! TKS!

+0

請不要輸入這樣的評論作爲答案。應嚴格用答案解答原始問題。謝謝。 – fred2

相關問題