lnmp環境搭建好後,,,,解析php檔案報錯 502

守護大白菜發表於2017-06-12

注:(nginx本身不能處理PHP,它只是個web伺服器,當接收到請求後,如果是php請求,則發給php直譯器處理,並把結果返回給客戶端。
nginx一般是把請求發fastcgi管理程式處理,fascgi管理程式選擇cgi子程式處理結果並返回被nginx

PHP-FPM其實是PHP原始碼的一個補丁,旨在將FastCGI程式管理整合進PHP包中。必須將它patch到你的PHP原始碼中,在編譯安裝PHP後才可以使用。)


測試伺服器相關目錄:

root目錄: /var/www/html   info.php


php.ini   php-fpm   目錄:
/etc/php/7.0/fpm
/etc/php/7.0/fpm/pool.d   下的 www.conf
php-fpm程式:
/run/php/php7.0-fpm.pid


問題1:404錯誤

2017/06/12 11:20:10 [alert] 63567#63567: 768 worker_connections are not enough

2017/06/12 11:20:10 [error] 63567#63567: *2296 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: www.hsx.com, request: "GET /info.php HTTP/1.0", upstream: "http://127.0.0.1:80/info.php", host: "127.0.0.1"

2017/06/12 11:20:10 [error] 63567#63567: *2296 open() "/usr/share/nginx/html/50x.html" failed (2: No such file or directory), client: 127.0.0.1, server: www.hsx.com, request: "GET /info.php HTTP/1.0", upstream: "http://127.0.0.1:80/info.php", host: "127.0.0.1"

原因未配置hosts檔案


問題2:  nginx不解析php檔案:

2017/06/12 13:50:35 [error] 65057#65057: *18 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /hxs.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"


解決給www.conf(php-fpm)中的

listen = /run/php/php7.0-fpm.sock  後新增 listen = 9000

然後重啟php-fpm           /etc/init.d/php/php-fpm.conf   restart



問題3: No input file specified.       修改nginx.conf配置
fastcgi_param     SCRIPT_FILENAME   /scripts$fastcgi_script_name;

參考文章:

https://myjeeva.com/php-fpm-configuration-101.html

https://stackoverflow.com/questions/21524373/nginx-connect-failed-111-connection-refused-while-connecting-to-upstream

http://niutuku.com/tech/php/273616.shtml




相關文章