Nginx + PHP-fpm File not found.問題解決記錄

來源:互聯網
上載者:User
這篇文章介紹的內容是關於Nginx + PHP-fpm File not found.問題解決記錄,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

現象確認:

開啟瀏覽器的開發人員工具,查看請求資訊


HTTP/1.1 404 Not Found

Server: nginx/1.11.10

Date: Fri, 20 Apr 2018 08:10:13 GMT

Content-Type: text/html; charset=UTF-8

Transfer-Encoding: chunked

Connection: keep-alive

X-Powered-By: PHP/5.6.30

說明結果是由FastCGI返回的。


問題原因:


估計是跟許可權有關係


相同的配置,使用以下兩個:

/opt/local/share/nginx/html  /opt/local/share/nginx/html/php

目錄都可以,但使用:

/Users/xxx/Downloads/workForder

目錄卻不可以。

通過 ls -l 查看許可權,發現區別在於


/Users/xxx/Downloads/workForder

目錄中的檔案沒有擴充屬性,也就是沒有@符號。


後來修改Nginx的靜態檔案root目錄到:


/Users/xxx/Downloads/workForder

訪問出現:

403 forbidden錯誤

再看 nginx 403 ,找到問題原因了,需要修改設定檔中的user 和 group。

nginx的格式是:

user 你的使用者名稱/root owner;比如:user root owner;

PHP-fpm的分別修改:

user = rootgroup = owner

然後重新啟動。

PHP-fpm 自身沒有重啟的命令,比較坑!只能殺進程了。

設定檔:

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        location ~ \.php$ {            root           /Users/xxx/Downloads/workForder;           # root           /opt/local/share/nginx/html/php;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            include        fastcgi.conf;         }

這裡只展示與PHP有關的部分。當我在配置中加入


try_files $uri =404;
 後,就會看到由Nginx返回的:



訪問PHP檔案時,你可能會看到下面這樣的錯誤:


那是因為FastCGI沒有啟動,需要啟動:

sudo php-fpm  -D

而如果Nginx和PHP的都指向同一個目錄,那麼還是會看到:

File not found

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.