手动编译php + nginx ,fastcgi模式.nginx配置好后,访问php一片空白

2013-11-17 15:37:36 +08:00
 letitbesqzr
nginx 配置:

------------------------------
#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /www/default;
index index.html index.htm index.php;
}

location ~.*\.php$ {
root /www/default;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}

------

$ netstat -anl | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN


------

每访问刷新一次

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:9000 127.0.0.1:34246 TIME_WAIT
tcp 0 0 127.0.0.1:9000 127.0.0.1:34245 TIME_WAIT
tcp 0 0 127.0.0.1:9000 127.0.0.1:34243 TIME_WAIT
tcp 0 0 127.0.0.1:9000 127.0.0.1:34247 TIME_WAIT


------

/www/default/
├── 1.txt
└── index.php

------

访问1.txt 正常... index.php内容:
<?php
phpinfo();
?>

访问index.php 一片空白,访问任何*.php 也是全空白。不提示404
12787 次点击
所在节点    Linux
13 条回复
shiny
2013-11-17 15:41:07 +08:00
http状态码呢?200还是500?看 nginx 错误日志?看 php 错误日志?
tywtyw2002
2013-11-17 15:49:20 +08:00
看下日志吧,估计是php报错。。
letitbesqzr
2013-11-17 15:49:39 +08:00
@shiny 2013/11/17 23:12:38 [error] 32394#0: *12 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
letitbesqzr
2013-11-17 15:49:59 +08:00
@tywtyw2002 2013/11/17 23:12:38 [error] 32394#0: *12 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
letitbesqzr
2013-11-17 15:53:13 +08:00
@tywtyw2002
@shiny

感谢。。一直用lnmp的一键安装,手动安装能力很差..一键安装包几乎没出什么错,也就没去关注过nginx的错误日志功能..下次一定注意了
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
加上这句话就成功了..
shiny
2013-11-17 16:25:56 +08:00
@letitbesqzr 其实用 dotdeb 源安装更方便,而且默认情况下不需要改配置。
princeofwales
2013-11-17 18:01:31 +08:00
前几天,抛弃用了3年的一键安装包,用dotdeb的源安装的
确实很快就装好了,配置还是需要改一点的,nginx里php部分,要反注释几行
richiefans
2013-11-17 18:17:04 +08:00
看看 这里面的配置 include fastcgi_params;
大部分情况是 fastcgi_param SCRIPT_FILENAME 的问题
letitbesqzr
2013-11-18 01:07:59 +08:00
@princeofwales
@richiefans
@shiny

...我用的这个senginx ...非常注重安全的一个版本..http://senginx.org/
bigwang
2013-11-18 04:11:24 +08:00
把php.ini中的display_errors 设置为On ,然后执行 /etc/init.d/php-fpm restart
txlty
2013-11-18 04:33:09 +08:00
内个,,解决问题了就不要顶了。。刚才我对照了半天,找到了问题。刚要回复,才发现你已经自己找到了。
上面有两位8楼、10楼,估计是没发现你已经解决问题了。
shiny
2013-11-18 11:39:07 +08:00
@letitbesqzr 程序写得好大部分情况下都不需要这个东西(比如防 SQL 注入、跨站脚本之类的,治标不治本)
防 DDoS 之类的一般是机房方面硬防的工作。Nginx 配置一般都是保持最简洁,很少让它介入安全方面的工作。并不觉得这种东西有什么必要。
不过带入的一些功能还蛮实用,比如 ifall 命令什么的……
coolicer
2013-11-18 14:35:18 +08:00
我现在跟你差不多,只是我的是502。访问静态文件正常,不知道是什么毛病

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://tanronggui.xyz/t/89596

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX