php` $ _SERVER ['PHP_SELF']`是空的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php` $ _SERVER ['PHP_SELF']`是空的相关的知识,希望对你有一定的参考价值。

我的nginxphp配置有问题。出于某种原因,$_SERVER['PHP_SELF']是空的。

我在跑步:

  • Ubuntu 18.04
  • nginx(nginx版本:nginx / 1.14.0(Ubuntu))
  • php(PHP 7.2.10-0ubuntu0.18.04.1)

我不知道可能导致这个问题的原因。我在网上看了很多,但找不到任何解决方案。

只是为了看看是否有更多的信息缺失,我检查了我从print_r($_SERVER);得到的,这是我得到的(截尾私人信息......):

数组([USER] => www-data [HOME] => / var / www [HTTP_COOKIE] => CENSORED [HTTP_ACCEPT_LANGUAGE] => en-GB,en; q = 0.9,he-IL; q = 0.8,he; q = 0.7,en-US; q = 0.6,ru; q = 0.5 [HTTP_ACCEPT_ENCODING] => gzip,deflate,br [HTTP_ACCEPT] => text / html,application / xhtml + xml,application / xml; q = 0.9, image / webp,image / apng,/; q = 0.8 [HTTP_USER_AGENT] => CENSORED [HTTP_UPGRADE_INSECURE_REQUESTS] => 1 [HTTP_CACHE_CONTROL] => max-age = 0 [HTTP_CONNECTION] => keep-alive [HTTP_HOST] => cumta。 morhaviv.com [SCRIPT_FILENAME] => /var/www/morhaviv.com/public_html/cumta/css/test.php [REDIRECT_STATUS] => 200 [SERVER_NAME] => www.cumta.morhaviv.com [SERVER_PORT] => 443 [SERVER_ADDR] => 153.92.209.235 [REMOTE_PORT] => 22964 [REMOTE_ADDR] => 176.231.2.86 [SERVER_SOFTWARE] => nginx / 1.14.0 [GATEWAY_INTERFACE] => CGI / 1.1 [HTTPS] => on [REQUEST_SCHEME] = > https [SERVER_PROTOCOL] => HTTP / 1.1 [DOCUMENT_ROOT] => /var/www/morhaviv.com/public_html/cumta [DOCUMENT_URI] => /css/test.php [REQUEST_URI] => /css/test.php [ SCRIPT_NAME] => /css/test.php [CONTENT_LENGTH] => [CONTENT_TYPE] => [REQUEST_METHOD] => GET [QUERY_STRING] => [PATH_INFO] => [FCGI_ROLE] => RESPONDER [PHP_SELF] => [REQUEST_TIME_FLOAT] => 1549710420.5126 [REQUEST_TIME] => 1549710420)

我的nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    include        fastcgi_params; 
    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

我知道这个问题可能缺少一些需要的信息,但我真的不知道还有什么重要的,所以请评论,我会添加缺少的信息。

谢谢您的帮助!

答案

确保在nginx配置文件中包含此行:

include fastcgi_params

除此之外,我认为没有理由不工作。

希望能帮助到你

另一答案

有关使用php安装nginx服务器的一些教程,坚持将php.ini文件的参数cgi.fix_pathinfo更改为0。

所以我的解决方案正在改变php.ini

cgi.fix_pathinfo = 0 

到默认值:

cgi.fix_pathinfo = 1

基本上就是这样。

解决方案被发现感谢kenzotenma对他的答案的评论,链接:https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/

以上是关于php` $ _SERVER ['PHP_SELF']`是空的的主要内容,如果未能解决你的问题,请参考以下文章

PHP $_SERVER['SCRIPT_FILENAME'] 与 __FILE__ 的区别

php` $ _SERVER ['PHP_SELF']`是空的

PHP $_SERVER['HTTP_REFERER'] 获取前一页面的 URL 地址

php$_SERVER['SCRIPT_NAME']和__FILE__的区别

php time() 和 $_SERVER['REQUEST_TIME']

PHP的$_SERVER['REMOTE_ADDR']