php fastcgi_param,nginx-404与root指令 fastcgi_param 指令
錯(cuò)誤日志
裝好 nginx-1.0.5 與 php-5.3.6(php-fpm) 迫不及待的測(cè)試 info.php(<?php phpinfo(); ?>),但是只返回了空白頁,什么也沒有輸出,以下是錯(cuò)誤日志。
192.168.6.82 - - [01/Aug/2011:13:54:20 +0800] "GET /info.php HTTP/1.1" 404 5 "-" "Mozilla/5.0(X11; U; Linux x86_64; zh-CN; rv:1.9.2.9) Gecko/20100827 Red Hat/3.6.9-2.el6 Firefox/3.6.9"
192.168.6.82 - - [01/Aug/2011:14:57:30 +0800] "HEAD /info.php HTTP/1.1" 404 0 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.12.6.2 zlib/1.2.3 libidn/1.18 libssh2/1.2.2"
192.168.6.82 - - [01/Aug/2011:13:58:57 +0800] "GET /index.html HTTP/1.1" 200 151 "-" "Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.9) Gecko/20100827 Red Hat/3.6.9-2.el6 Firefox/3.6.9"
分析
1 使用firefox 瀏覽 http://192.168.5.87/info.php 測(cè)試頁返回空白頁,什么都沒有。
2 使用curl? 測(cè)試 http://192.168.5.87/info.php 測(cè)試頁提示404沒找到。
# curl -I http://192.168.5.87/info.php
HTTP/1.1 404 Not Found
Server: nginx/1.0.5
Date: Mon, 01 Aug 2011 06:54:46 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.3.6
3 使用firefox? 瀏覽 http://192.168.5.87/index.html
4 靜態(tài)頁面的index.html 是可以訪問的,而動(dòng)態(tài)的info.php確是404 找不到,為什么會(huì)這樣那?index.html 文件目錄是nginx默認(rèn)安裝目錄 /usr/local/nginx/html,而
info.php 我把它放到了 /data/web 下 是不是這個(gè)原因 ?看下nginx.conf配置文檔
server {
listen?????? 80;
server_name? localhost;
location / {
index? index.html index.htm;
root?? html;
}
error_page?? 500 502 503 504? /50x.html;
location = /50x.html {
root?? html;
}
location ~ \.php$ {
fastcgi_pass?? 127.0.0.1:9000;
fastcgi_index? index.php;
fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
include??????? fastcgi_params;
}
}
過程
嘗試更改下
location ~ \.php$ {
root?????????? /data/web;
fastcgi_pass?? 127.0.0.1:9000;
fastcgi_index? index.php;
fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
include??????? fastcgi_params;
}
nginx -t && nginx -s reload
測(cè)試訪問仍然不行
再次更改
location ~ \.php$ {
root?????????? /data/web;
fastcgi_pass?? 127.0.0.1:9000;
fastcgi_index? index.php;
fastcgi_param? SCRIPT_FILENAME /data/web$fastcgi_script_name;
include??????? fastcgi_params;
}
nginx -t && nginx -s reload
測(cè)試一下
[root@me zongm]# curl -I http://192.168.5.87/info.php
HTTP/1.1 200 OK
Server: nginx/1.0.5
Date: Mon, 01 Aug 2011 08:34:17 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.3.6
firefox 測(cè)試ok!
總結(jié)
問題還是在配置文檔上,估計(jì)不少朋友會(huì)遇到php 輸出空白頁什么也不顯示,
主要是nginx 的 root 指令 或者 fastcgi_param 指令 配置出了問題詳細(xì)的文檔請(qǐng)參考這里!
再看下nginx.conf配置文檔,
server{
location / {
index? index.html index.htm;
root?? html;
}
location = /50x.html {
root?? html
}
location ~ \.php$ {
fastcgi_pass?? 127.0.0.1:9000;
fastcgi_index? index.php;
fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
include??????? fastcgi_params;
}
}
1 發(fā)現(xiàn)除了location ~ \.php$以外,每個(gè)location 下都有個(gè)root 指令用于載入web文件根目錄,默認(rèn)都是 /usr/local/nginx/html,第一個(gè)錯(cuò)誤是沒有在 location ~ \.php$ 添加web文件根目錄
root? /data/web;
或者在server 字段下加入一個(gè) root 例如
server {
.........
root? /data/web;
.........
}
2 參考這里知道了 PHP使用fastcgi_param 指令的 SCRIPT_FILENAME參數(shù)決定需要執(zhí)行哪個(gè)腳本,所以這個(gè)位置也要改成
fastcgi_param? SCRIPT_FILENAME/data/web$fastcgi_script_name;
總結(jié)
以上是生活随笔為你收集整理的php fastcgi_param,nginx-404与root指令 fastcgi_param 指令的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java中有几种内部类,Java中的四种
- 下一篇: 找出最大和第二大的数PHP,2020-0