Ngnix - 在 stderr 中发送的 FastCGI:“PHP 消息:PHP 通知:未定义变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34301099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:54:09  来源:igfitidea点击:

Ngnix - FastCGI sent in stderr: "PHP message: PHP Notice: Undefined variable

phpnginxfastcgi

提问by ohadsas

I've installed an Ngnix server and configured it like:

我已经安装了 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;
    #}

}

}

I'm getting these errors (copied from my error.log) :

我收到这些错误(从我的 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-interface/login.php on line 245 PHP message: PHP Notice: Undefined index: username in /usr/share/nginx/html/admin-interface/login.php on line 249" 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"

    *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 在 stderr 中发送:“PHP 消息:PHP 通知:未定义索引:用户名在 /usr/share/nginx/html/admin-interface/login .php on line 245 PHP message: PHP Notice: Undefined index: username in /usr/share/nginx/html/admin-interface/login.php on line 249" while reading upstream, client: 127.0.0.1, server: localhost,请求:“GET /admin-interface/login.php HTTP/1.1”,上游:“fastcgi://unix:/var/run/php5-fpm.sock:”,主机:“localhost”

I'm trying to configure this environment using an Ngnix server, this environment does work using different hosting. I did change the cgi.fix_pathinfo = 0 in my php.ini

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

What am i missing with my configuration?

我的配置缺少什么?

采纳答案by Daniel W.

It's not an error, it's a notice.

这不是错误,是通知

The script /usr/share/nginx/html/admin-interface/login.phpis accessing the variable $confMsgwhich does not exist at that point.

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

You can either change the error reporting level in php.ini(which has impact on other scripts too and you don't want to turn off notices..) or fix the wrong variable access in the script.

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

The second solution would be easier because you'd just had to initialize $confMsg = '';.

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

回答by Mathieu Aubin

I'm sorry to say this question is so vague it's hard to answer... What is the problem??

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

As far as i can see from the error file, there is no problem here. Just PHP Notices.

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

Look at this:

看这个:

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

Can't you see anything wrong? You are including the / location into the error location, not logic my friend... Your php files under "/" will never be passed on to php5-fpm that way. Unless i understand nothing from what you are asking, do this;

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

remove;

消除;

location = /50x.html {

and downwards.

和向下。

add this instead:

添加这个:

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

then;

然后;

sudo nginx -t # to test your config.

If there's a problem, look for opening and closing brackets as this seem to be your nemesis (you are in the server block which you opened a bracket for - make sure you close it). If all pass;

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

sudo nginx -s reload

And please, next time you post code, take a second to remove all the junk comments. That'll help you get answers or at least interrest to your question.

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

If all is good then, you might consider adding theses location configurations for a more robust/efficient server;

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

# 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; }

if you don't understand a setting, don't add it. It would be like blindly putting fuel in your car without knowing what type it is.

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