[error] 1507#0: *22 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.0.0.1, server: www.wordpress.com, request: "GET /info.p


字體比較小,如果你遇到這個問題請仔細的把下面的總結看完。

環境:CentOS6.7、2.6.32-573.el6.x86_64、nginx1.12.2 、php5.5.38

問題:nginx能解析靜態文件但是不能解析php動態文件,返回404文件未發現錯誤

原始nginx配置:(這里只給出拋給php程序的配置)

1         location ~ \.php$ {
2             root           html/wordpress;
3             fastcgi_pass   127.0.0.1:9000;
4             fastcgi_index  index.php;
5             fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
6             include        fastcgi_params;
7 
8     }

解決方案:

  方案一:在配置最后一行包含fastcgi.conf配置文件,結果如下

 1    location ~ \.php$ {
 2             root           html/wordpress;
 3             fastcgi_pass   127.0.0.1:9000;
 4             fastcgi_index  index.php;
 5             fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
 6             include        fastcgi_params;
 7 
 8             include        fastcgi.conf;
 9 
10     }

  方案二:把fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;這一行,改為:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

結果如下:

     location ~ \.php$ {
            root           html/wordpress;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;

    }

原因:

在fastcgi_params文件(和nginx.conf文件在同一個目錄下)里定義了許多與fastcgi程序相關的變量,當nginx通過fastcgi接口發送請求時它要去定義好的地方去解析相應的變量值,然后交給php去處理,很顯然,如果fastcgi獲取不了相應的值,那么他就無法把相應請求轉發給php程序,自然無法解析。

這個問題的關鍵在於"Primary script unknown”主腳本未知,也就是fastcgi程序無法找到定義的要執行的腳本,默認的配置文件fastcgi_params定義的變量中並沒有$fastcgi_script_name這個變量,但是在fastcgi.conf里定義了。所以我們要么包含這個fastcgi.conf文件,要么把fastcgi_params里的SCRIPT_FILENAME 構建成和fastcgi.conf里的值一樣,加上$document_root參數(這個參數的值就代表站點目錄root那一行的值)。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM