Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9268194
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 网络与安全

2013-11-27 13:13:57

nginx-404与root指令 fastcgi_param 指令
2011-08-01 17:21:46
标签:nginx 404 休闲 php-fpm linux
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://dngood.blog.51cto.com/446195/628699

错误日志

装好 nginx-1.0.5 与 php-5.3.6(php-fpm) 迫不及待的测试 info.php(),但是只返回了空白页,什么也没有输出,以下是错误日志。

 

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 浏览 测试页返回空白页,什么都没有。

 

2 使用curl  测试 测试页提示404没找到。

# curl -I
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  浏览

4 静态页面的index.html 是可以访问的,而动态的info.php确是404 找不到,为什么会这样那?index.html 文件目录是nginx默认安装目录 /usr/local/nginx/html,而

info.php 我把它放到了 /data/web 下 是不是这个原因 ?看下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

测试访问仍然不行

google 

再次更改

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

测试一下

[root@me zongm]# curl -I
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 测试ok!

 

总结

问题还是在配置文档上,估计不少朋友会遇到php 输出空白页什么也不显示,

主要是nginx 的 root 指令 或者 fastcgi_param 指令 配置出了问题详细的文档请!

再看下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 发现除了location ~ \.php$以外,每个location 下都有个用于载入web文件根目录,默认都是 /usr/local/nginx/html,第一个错误是没有在 location ~ \.php$ 添加web文件根目录

root  /data/web;

或者在server 字段下加入一个 root 例如

server {

.........

root  /data/web;

.........

}

 

2 知道了 PHP使用的 SCRIPT_FILENAME参数决定需要执行哪个脚本,所以这个位置也要改成

fastcgi_param  SCRIPT_FILENAME  /data/web$fastcgi_script_name;

 

本文出自 “dongnan” 博客,请务必保留此出处http://dngood.blog.51cto.com/446195/628699

阅读(1309) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~