V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
letitbesqzr
V2EX  ›  Linux

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

  •  
  •   letitbesqzr · 2013-11-17 15:37:36 +08:00 · 12637 次点击
    这是一个创建于 3830 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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
    13 条回复    1970-01-01 08:00:00 +08:00
    shiny
        1
    shiny  
       2013-11-17 15:41:07 +08:00   ❤️ 1
    http状态码呢?200还是500?看 nginx 错误日志?看 php 错误日志?
    tywtyw2002
        2
    tywtyw2002  
       2013-11-17 15:49:20 +08:00   ❤️ 1
    看下日志吧,估计是php报错。。
    letitbesqzr
        3
    letitbesqzr  
    OP
       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
        4
    letitbesqzr  
    OP
       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
        5
    letitbesqzr  
    OP
       2013-11-17 15:53:13 +08:00
    @tywtyw2002
    @shiny

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

    ...我用的这个senginx ...非常注重安全的一个版本..http://senginx.org/
    bigwang
        10
    bigwang  
       2013-11-18 04:11:24 +08:00
    把php.ini中的display_errors 设置为On ,然后执行 /etc/init.d/php-fpm restart
    txlty
        11
    txlty  
       2013-11-18 04:33:09 +08:00
    内个,,解决问题了就不要顶了。。刚才我对照了半天,找到了问题。刚要回复,才发现你已经自己找到了。
    上面有两位8楼、10楼,估计是没发现你已经解决问题了。
    shiny
        12
    shiny  
       2013-11-18 11:39:07 +08:00
    @letitbesqzr 程序写得好大部分情况下都不需要这个东西(比如防 SQL 注入、跨站脚本之类的,治标不治本)
    防 DDoS 之类的一般是机房方面硬防的工作。Nginx 配置一般都是保持最简洁,很少让它介入安全方面的工作。并不觉得这种东西有什么必要。
    不过带入的一些功能还蛮实用,比如 ifall 命令什么的……
    coolicer
        13
    coolicer  
       2013-11-18 14:35:18 +08:00
    我现在跟你差不多,只是我的是502。访问静态文件正常,不知道是什么毛病
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1143 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:45 · PVG 02:45 · LAX 11:45 · JFK 14:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.