問題場景:
nginx經過了簡單的配置,開始試驗是否可以支持php
location / { root html; index index.html index.htm index.php; } location ~ /.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
在瀏覽器訪問 localhost/index.php
結果為 File not found.
這時候我們查看nginx的錯誤日志,錯誤日志的主要內容為 FastCGI sent in stderr: "Primary script unknown"
經過分析+搜索前輩經驗得出結論,nginx的配置文件無法識別/scripts
路徑,所以我們將配置文件中的/scripts
改為$document_root
,或者web目錄的絕對路徑。更改后的配置文件如下:
location ~ /.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
重啟nginx服務器,已經可以正確顯示phpinfo()
的內容了。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
新聞熱點
疑難解答
圖片精選