問題場景:
- linux系統
- nginx服務器
- 安裝好了fpm的php7
- 在nginx的web目錄下新建了index.php文件,內容為phpinfo()函數。(如果是源碼安裝,位置一般為 /usr/local/nginx/html/index.php)
nginx經過了簡單的配置,開始試驗是否可以支持php
1 2 3 4 5 6 7 8 9 10 11 12 | 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目錄的絕對路徑。更改后的配置文件如下:
1 2 3 4 5 6 7 | 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()
的內容了。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。