PATH_INFO in $_SERVER always empty - NGINX + FPM 7.3 + Ubuntu 18.04

自古美人都是妖i 提交于 2021-01-29 11:23:23

问题


I am deploying my web application at DigitalOcean. My environment is: Ubuntu 18.04, PHP + FPM 7.3, NGINX.

My routing system is based on the $_SERVER PATH_INFO, but it only returns empty, so I can't access my routes. I already researched the solution and none of StackOverflow worked for me.

My default file in /etc/nginx/sites-enabled is:

server {
    listen 80;
    listen [::]:80;

    root /usr/share/nginx/my-site/public;
    index index.php index.html index.htm;

    server_name localhost;  

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}

My fastcgi.conf is:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  PATH_INFO          $fastcgi_path_info;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

My var_dump of $_SERVER when accessing my-domain/admin is:

array (
  'USER' => 'www-data',
  'HOME' => '/var/www',
  'HTTP_ACCEPT_LANGUAGE' => 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',
  'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
  'HTTP_CACHE_CONTROL' => 'max-age=0',
  'HTTP_CONNECTION' => 'keep-alive',
  'REDIRECT_STATUS' => '200',
  'SERVER_NAME' => 'localhost',
  'SERVER_PORT' => '80',
  'SERVER_SOFTWARE' => 'nginx/1.14.0',
  'GATEWAY_INTERFACE' => 'CGI/1.1',
  'REQUEST_SCHEME' => 'http',
  'SERVER_PROTOCOL' => 'HTTP/1.1',
  'DOCUMENT_ROOT' => '/usr/share/nginx/my-site/public',
  'DOCUMENT_URI' => '/index.php',
  'REQUEST_URI' => '/admin',

  'PATH_INFO' => '',

  'SCRIPT_NAME' => '/index.php',
  'REQUEST_METHOD' => 'GET',
  'SCRIPT_FILENAME' => '/usr/share/nginx/my-site/public/index.php',
  'FCGI_ROLE' => 'RESPONDER',
  'PHP_SELF' => '/index.php',
)

(Note: I hid some items of _$SERVER for safety of the stretch above).

What am I doing wrong? Thank you very much.

来源:https://stackoverflow.com/questions/56640592/path-info-in-server-always-empty-nginx-fpm-7-3-ubuntu-18-04

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!