请帮我一个问题!

enter image description here

和索引.类似php

enter image description here

当我输入浏览器mysite/blablabla时,我得到

enter image description here

但当我键入"mysite/folder1"时,浏览器只需打开这个文件夹.

如何获取REUEST\u URI,如"mysite/folder1"或"mysite/folder2"

我使用OpenServer(nginx).对不起,如果我解释的英语很差,很糟糕.

此文件:nginx.来自C的配置:/nginx

http {
include       mime.types;
default_type  application/octet-stream;
sendfile        off;
keepalive_timeout  65;


server {
    listen       80;
    server_name  onix-academy-php-framework;
    root   d:/dropbox/onix-academy-php-framework;
    index  index.php;
    #autoindex  on;
    
    location / {
       try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
       fastcgi_pass  127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include       fastcgi_params;
   }
}

此文件:nginx.来自OpenServer的配置

server {
listen                    %ip%:%httpport%;
listen                    %ip%:%httpsport% ssl;
server_name               %host% %aliases%;
root                      '%hostdir%';
#autoindex                 on;
index                     index.php index.html index.htm;

ssl_certificate           '%sprogdir%/userdata/config/cert_files/server.crt';
ssl_certificate_key       '%sprogdir%/userdata/config/cert_files/server.key';
#ssl_trusted_certificate  '';

# Disable MIME sniffing
add_header X-Content-Type-Options 'nosniff' always;

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

    location ~ \.php$ {
        try_files      $fastcgi_script_name =404;
        fastcgi_pass   backend;
        include        '%sprogdir%/userdata/config/nginx_fastcgi_params.txt';
    }
    
    #location ^~ /Classes/ {
    #   return 302 /;
    #}
}

When I use "autoindex on" folders just open: enter image description here

And when I commented "#autoindex on" I get 403 forbidden: enter image description here

推荐答案

您需要设置nginx以发送所有传入请求,并将其切换到PHP.

Symfony has a simple setup份文件.虽然它是为symfony定制的,但它也可以用于标准PHP.

try 用以下内容替换第一次配置的server部分

server {
    listen       80;
    server_name  onix-academy-php-framework;
    root   d:/dropbox/onix-academy-php-framework;
    index  index.php;
    #autoindex  on;

    location / {
       try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
       fastcgi_pass  127.0.0.1:9000;

       # not sure if this one is needed, try it with or without:
       fastcgi_split_path_info ^(.+\.php)(/.*)$;

       fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
       fastcgi_param DOCUMENT_ROOT $realpath_root;
       include       fastcgi_params;
   }
}

Php相关问答推荐

Laravel 11发送邮箱时奇怪的未定义数组键名称

模型中的Laravel自定义查询字段

使用箭头函数语法时,在回调范围内无法访问变量变量(警告:未定义的变量)

Laravel集合块()方法

在AJAX请求后,Laravel重定向.(不允许使用方法)

获取并判断WooCommerce用户订阅结束日期

Apache只允许index.php-不从根目录工作

创建一个Woocommerce我的帐户订单页面,仅显示已完成的订单

如何使用定制的StateProvider设置JsonLd@上下文?

如何配置我的.env文件以在laravel的一个项目中连接两个不同的数据库?

在 PHP MySQL 中自动生成账单编号

AWS S3:当对象名称包含 % 时复制对象失败并出现错误 - 无效的复制源编码

PHP 简单 XML Xpath 上移树(带有名称的父级)

在 PHP 8.2 中使用 PHP Spreadsheet 和 CodeIgniter 3 导出 Excel 时出错

PHP for each 函数打印 td

如何使用属性创建属性预设?

如何在光速网络服务器中使用 apache ..htaccess

为什么可以从 PHP 类访问 PHP Trait 的私有成员?

Laravel 响应 html 默认页面忽略控制器

如何使用先前 SELECT 的结果来 SELECT SQL 数据