1. 程式人生 > >測試PHP是否安裝成功時,nginx報錯:"Primary script unknown"

測試PHP是否安裝成功時,nginx報錯:"Primary script unknown"

stderr php pri index known req tde stc 參數

小生博客:http://xsboke.blog.51cto.com

小生 Q Q:1770058260
-------謝謝您的參考,如有疑問,歡迎交流


  1. 環境
    php-5.6.36
    nginx-1.14.0
  2. 問題
    訪問php測試文件時報404(文件不存在),已經確認權限和配置都沒有問題。
  3. 處理過程
    查看nginx錯誤日誌:報如下錯誤(172.16.6.236是服務器)
    2018/08/03 01:05:34 [error] 57141#0: *242 FastCGI sent in stderr: "Primary script unknown" while reading
    response header from upstream, client: 172.16.6.237, server: localhost, request: "GET /test.php HTTP/1.1",
    upstream: "fastcgi://127.0.0.1:9000", host: "172.16.6.236"
  4. 解決過程
    在nginx官網查看有沒有類似錯誤,發現沒有,然後百度。。。。(笑哭)
    解決辦法如下,
    將:#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    修改為:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    解釋:$document_root 就是nginx配置項“root”指定的位置參數的變量

測試PHP是否安裝成功時,nginx報錯:"Primary script unknown"