PHP-FPM:來自 nginx/error.log 的「沒有此類檔案或目錄」錯誤。路徑或權限問題?

PHP-FPM:來自 nginx/error.log 的「沒有此類檔案或目錄」錯誤。路徑或權限問題?

當我在瀏覽器列中輸入我的wiki 位址時,收到“FastCGI 在stderr 中發送:“無法開啟主腳本:/var/www/mediawiki/index.php(沒有此類文件或目錄)””錯誤。這是我的 PHP-FPM www.conf 檔案:

[www]
user = nginx
group = nginx
listen = /var/run/php/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
;chroot = 
;chdir = 
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache
php_value[opcache.file_cache]  = /var/lib/php/opcache

這是我的 nginx conf.d 檔案:

# HTTP requests will be redirected to HTTPS

server {
    listen 80;
    listen [::]:80;
    server_name wiki.example.com;
    return 301 https://$host$request_uri;
}

# HTTPS Configuration

server {
    listen 443 ssl;
    listen [::]:443;

    server_name wiki.example.com;
    root /var/www/mediawiki;

    index index.php;
    autoindex off;

    # SSL Certification Configuration

    ssl_certificate 
      /etc/letsencrypt/live/wiki.example.com/fullchain.pem;
    ssl_certificate_key 
      /etc/letsencrypt/live/wiki.example.com/privkey.pem;

    client_max_body_size 5m;
    client_body_timeout 60;

    location / {
    try_files $uri $uri/ @rewrite;
    }

    location @rewrite {
    rewrite ^/(.*)$ /index.php?title=$1&$args;
    }

    location ^~ /maintenance/ {
    return 403;
    }

    #PHP-FPM Configuration NGINX

    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    try_files $uri /index.php;
    expires max;
    log_not_found off;
}

location = /_.gif {
    expires max;
    empty_gif;
}

location ^~ 
^/(cache|includes|maintenance|languages|serialized|tests|images/deleted)/ {
    deny all;
}

location ^~ ^/(bin|docs|extensions|includes|maintenance|mw- 
config|resources|serialized|tests)/ {
    internal;
}

# Security for 'image' directory
location ~* images/.*.(html|htm|shtml|php)$ {
    allow all;
    types {}
    default_type text/plain;
}

# Security for 'image' directory
location ^~ /images/ {
    allow all;
    try_files $uri /index.php;
}

}

我覺得這是一個權限問題,或者 php-fpm 守護程式正在尋找冗餘檔案路徑或其他內容。我嘗試透過 nginx conf.d 檔案將絕對路徑傳遞給 FPM,方法是:

fastcgi_param SCRIPT_FILENAME /var/www/mediawiki/index.php;

無濟於事。所以我知道我將它指向正確的方向,但它仍然給我同樣的錯誤,這讓我相信我有權限問題。我也嘗試過:

setenforce 0

但這也行不通。我已經 chmod 777 整個目錄,包括 index.php 檔案。

一些背景:

我想安裝一個wikimedia 擴展,它需要新版本的php (7.0+),而我運行的是5.4,因為它隨CentOS 7 的基本安裝一起提供。 php *,從 remi 安裝了 php73,刪除了它,重新安裝了 php 5.4,最後發現我可以透過啟用 remi-php71.repo 進行 yum update 來更新我的基礎包。但是,我在此過程中丟失了 .conf 和 php.ini 檔案。

編輯:

/var/log/nginx/error.log 當我在瀏覽器中造訪我的網站時:

2019/01/22 16:58:19 [error] 10876#0: *1 FastCGI sent in stderr: "Unable to 
open primary script: /var/www/mediawiki/index.php (No such file or 
directory)" while reading response header from upstream, client: 
10.11.190.1, server: wiki.example.com, request: "GET / HTTP/1.1", 
upstream: "fastcgi://unix:/var/run/php/php-fpm/php-fpm.sock:", host: 
"wiki.example.com"

/var/log/php-fpm/www-access.log:

- 22/Jan/2019:16:58:19 -0700 "GET /index.php" 404 
/var/www/mediawiki/index.php /var/www/mediawiki /index.php /index.php

答案1

cgi.fix_pathinfo=0我修好了它,感謝克里斯托弗透過他的詢問為我指明了正確的方向php.ini

他的具體問題沒有解決問題,但我繼續嘗試附近的cgi.fix_pathinfo=0設置php.ini並且能夠從 PHP-FPM 收到一條不同的錯誤訊息,沒有錯誤,抱怨無法開啟/var/www/mediawiki/index.php.

這個問題花了我整整 5 天的時間才解決。我真的很感謝克里斯托弗的幫助!

我最終評論了以下幾行php.ini

;cgi.fixpathinfo=0
;user_dir=/var/www/mediawiki    **This is the one that changed the error message

一旦我改變了它,我得到了一個InvalidArgumentException這是由於php-mysqlnd我從 5.4 > 7.1 升級時沒有安裝。

一旦我安裝了它,bam,wiki 就恢復並運行了。

我想繞著大樓跑五圈。再次感謝克里斯多福為我指明了正確的方向!

約旦

相關內容