【问题标题】:Ngnix - FastCGI sent in stderr: "PHP message: PHP Notice: Undefined variableNginx - 在标准错误中发送的 FastCGI:“PHP 消息:PHP 通知:未定义的变量
【发布时间】:2016-03-21 22:40:13
【问题描述】:

我已经安装了 Ngnix 服务器并将其配置为:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #       proxy_pass http://127.0.0.1:8080;    
    #}
    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = / {
      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #       # With php5-cgi alone:
    #       fastcgi_pass 127.0.0.1:9000;
    #       # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #       deny all;
    #}

}

我收到了这些错误(从我的 error.log 复制):

    *9 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined variable: confMsg in /usr/share/nginx/html/admin-interface/login.php on line 196" while reading upstream, client: 127.0.0.1, server: localhost, request: "GET /admin-interface/login.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost"

2015/12/16 00:27:37 [error] 952#0: *9 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: username in /usr/share/nginx/html/admin-第 245 行的 interface/login.php PHP 消息:PHP 通知:未定义索引:/usr/share/nginx/html/admin-interface/login.php 中的用户名在第 249 行,同时读取上游,客户端:127.0.0.1,服务器:localhost,请求:“GET / admin-interface/login.php HTTP/1.1”,上游:“fastcgi://unix:/var/run/php5-fpm.sock:”,主机:“localhost”

我正在尝试使用 Ngnix 服务器配置这个环境,这个环境使用不同的主机工作。 我确实在我的 php.ini 中更改了 cgi.fix_pathinfo = 0

我的配置缺少什么?

【问题讨论】:

    标签: php nginx fastcgi


    【解决方案1】:

    抱歉,这个问题太模糊了,很难回答…… 有什么问题??

    据我从错误文件中可以看出,这里没有问题。只是 PHP 通知。

    看看这个:

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    

    你看不出有什么不对吗?您将 / 位置包含在错误位置中,而不是逻辑我的朋友......您在“/”下的 php 文件永远不会以这种方式传递给 php5-fpm。除非我对您的要求一无所知,否则请这样做;

    删除;

    location = /50x.html {
    

    向下。

    改为添加:

    location ~ [^/]\.php(/|$) { #open location bracket
    
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) { #open condition bracket
            return 404;
        } #close condition bracket
    
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    
    } #close location bracket
    

    那么;

    sudo nginx -t # to test your config.
    

    如果有问题,请寻找左括号和右括号,因为这似乎是您的克星(您在为它打开括号的服务器块中 - 确保关闭它)。如果全部通过;

    sudo nginx -s reload
    

    请在下次发布代码时花一点时间删除所有垃圾 cmets。这将帮助您获得问题的答案或至少对您的问题感兴趣。

    如果一切顺利,您可以考虑添加这些位置配置以获得更强大/高效的服务器;

    # send expire headers
    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off; # optional
        log_not_found off; # optional
        expires max;
    }
    
    location = ^/favicon.ico {
        access_log off;
        log_not_found off;
    }
    
    # robots noise...
    location = ^/robots.txt {
        log_not_found off;
        access_log off;
        allow all;
    }
    
    # block access to hidneen files (.htaccess per example)
    location ~ /\. { access_log off; log_not_found off; deny all; }
    

    如果您不了解某个设置,请不要添加它。这就像在不知道它是什么类型的情况下盲目地给汽车加油一样。

    【讨论】:

      【解决方案2】:

      这不是错误,这是通知。

      脚本/usr/share/nginx/html/admin-interface/login.php 正在访问当时不存在的变量$confMsg。

      您可以更改php.ini 中的错误报告级别(这也会影响其他脚本,您不想关闭通知..)或修复脚本中错误的变量访问。

      第二种解决方案会更简单,因为您只需初始化 $confMsg = '';。

      【讨论】:

        猜你喜欢
        • 2017-11-02
        • 1970-01-01
        • 2015-11-07
        • 1970-01-01
        • 2012-10-21
        • 2015-12-06
        • 1970-01-01
        • 1970-01-01
        • 2020-08-20
        相关资源
        最近更新 更多