請幫我解決一個問題!我的專案結構如下:

和 index.php 一樣

當我在瀏覽器 mysite/blablabla 中輸入時,我得到了

但是當我輸入“mysite/folder1”時——瀏覽器只打開這個檔案夾。
如何獲得 REUEST_URI,如“mysite/folder1”或“mysite/folder2”
我使用 OpenServer (nginx)。對不起,如果我解釋得不好,英語不好。
這個檔案:來自 C:/nginx 的 nginx.conf
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;
}
}
這個檔案:來自 OpenServer 的 nginx.conf
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 /;
#}
}
當我使用“autoindex on”檔案夾時,只需打開:

當我評論“#autoindex on”時,我得到 403 禁止:

uj5u.com熱心網友回復:
您需要設定您的 nginx 以將所有傳入請求發送到 PHP。
Symfony 記錄了一個簡單的設定。雖然它是為 symfony 量身定做的,但它也可以用于標準 PHP。
嘗試用這個替換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;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/498030.html
