我正在DigitalOcean部署我的Web应用程序。 我的环境是:Ubuntu 18.04,PHP + FPM 7.3,NGINX。
我的路由系统基于$ _SERVER PATH_INFO,但它仅返回空值,因此我无法访问我的路由。 我已经研究了该解决方案,而StackOverflow都不适合我。
我在/etc/nginx/sites-enabled
中的默认文件是:
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;
}
}
我的fastcgi.conf
是:
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;
访问我的域/管理员时,我在var_dump
中的$_SERVER
是:
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',
)
(注意:为了安全起见,我隐藏了_ $ SERVER的某些项目)。
我在做什么错?非常感谢。