Каждый экземпляр приложения находится внутри директора, например:
Применение.
Код: Выделить всё
├── oldsite
│ ├── index.php
│ ├── javascript.php
│ ├── mod
│ │ └── book
│ │ └── index.php
│ └── r.php
└── newsite
└── public
├── index.php
├── javascript.php
├── mod
│ └── book
│ └── index.php
└── r.php
Я стараюсь (и терпит неудачу), чтобы написать конфигурацию nginx, которая будет автоматически обрабатывать как старые, так и новые сайты. Что у меня есть до сих пор: < /p>
Код: Выделить всё
set $root /srv/sites
index index.php;
set $site "";
if ($uri ~ /(?[^/]+)(?/?.*)) {
set $site $site;
}
set $docroot "$root/$site";
if (-d "/$docroot/public") {
set $docroot "$root/$site/public";
}
location ~ /(?[^/]+)(?/.*\.php)(/?|$) {
root $docroot;
include /opt/homebrew/etc/nginx/blocks/php.conf;
}
location ~ ^/(?[^/]+)/?$ {
root $docroot;
rewrite ^(.*)/?$ $1/index.php last;
location ~ \.php$ {
include /opt/homebrew/etc/nginx/blocks/php.conf;
}
}
location ~ ^/(?[^/]+)/?(?.*)$ {
root $docroot;
location ~ \.php$ {
include /opt/homebrew/etc/nginx/blocks/php.conf;
}
try_files /$relpath /$relpath/ /r.php;
}
< /code>
my php.conf выглядит следующим образом: < /p>
fastcgi_split_path_info ^(.+\.php)(/.*)$;
# Save path_info before try_files resets it
set $path_info $fastcgi_path_info;
include fastcgi_params;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $docroot$relpath;
fastcgi_param DOCUMENT_ROOT $docroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
< /code>
Что работает: < /p>
[list]
[*]http://example.com/oldsite< /code> (return /index.php)
[*]http://example.com/oldsite/< /code> (return /index.php)
[*]http://example.com/oldsite/index.phpКод: Выделить всё
http://example.com/oldsite/javascript.php/some/fileКод: Выделить всё
http://example.com/oldsite/mod/book/index.phpКод: Выделить всё
http://example.com/newsite< /code> (return /index.php)
[*]http://example.com/newsite/< /code> (return /index.php)
[*]http://example.com/newsite/index.phpКод: Выделить всё
http://example.com/newsite/mod/book/index.phpКод: Выделить всё
http://example.com/newsite/javascript.php/some/file< /code> < /li>
< /ul>
Что не работает: < /p>
http://example.com/oldsite/notfound< /code> (возвращает 404) - должен использовать /р.php
[*]http://example.com/oldsite/mod/book[*]
Код: Выделить всё
http://example.com/oldsite/mod/book/[/list]
Копание в журналах используется окончательное соответствие местоположения (правильно), но директива try_files не работает, как я ожидаю.
try_files не работает.
Код: Выделить всё
2025/06/05 09:00:22 [debug] 80884#0: *31 generic phase: 13
2025/06/05 09:00:22 [debug] 80884#0:*31 try files handler
2025/06/05 09:00:22 [debug] 80884#0: *31 http script var: "/srv/sites/newsite/public"
2025/06/05 09:00:22 [debug] 80884#0:*31 http script copy: "/"
2025/06/05 09:00:22 [debug] 80884#0: *31 http script var: "mod/book/"
2025/06/05 09:00:22 [debug] 80884#0:*31 trying to use file: "/mod/book/" "/srv/sites/newsite/public/mod/book/"
2025/06/05 09:00:22 [debug] 80884#0: *31 http script copy: "/"
2025/06/05 09:00:22 [debug] 80884#0:*31 http script var: "mod/book/"
2025/06/05 09:00:22 [debug] 80884#0: *31 trying to use dir: "/mod/book/" "/srv/sites/newsite/public/mod/book/"
2025/06/05 09:00:22 [debug] 80884#0:*31 try file uri: "/mod/book/"
2025/06/05 09:00:22 [debug] 80884#0: *31 generic phase: 14
2025/06/05 09:00:22 [debug] 80884#0:*31 content phase: 15
2025/06/05 09:00:22 [debug] 80884#0: *31 content phase: 16
2025/06/05 09:00:22 [debug] 80884#0:*31 http script var: "/srv/sites/newsite/public"
2025/06/05 09:00:22 [debug] 80884#0: *31 open index "/srv/sites/newsite/public/mod/book/index.php"
2025/06/05 09:00:22 [debug] 80884#0:*31 internal redirect: "/mod/book/index.php?"
Код: Выделить всё
2025/06/05 07:00:29 [debug] 80884#0: *11 try files handler
2025/06/05 07:00:29 [debug] 80884#0: *11 http script var: "/srv/sites/newsite/public"
2025/06/05 07:00:29 [debug] 80884#0: *11 http script copy: "/"
2025/06/05 07:00:29 [debug] 80884#0: *11 http script var: "mod/book/notfound"
2025/06/05 07:00:29 [debug] 80884#0: *11 trying to use file: "/mod/book/notfound" "/srv/sites/newsite/public/mod/book/notfound"
2025/06/05 07:00:29 [debug] 80884#0: *11 http script copy: "/"
2025/06/05 07:00:29 [debug] 80884#0: *11 http script var: "mod/book/notfound"
2025/06/05 07:00:29 [debug] 80884#0: *11 trying to use dir: "/mod/book/notfound" "/srv/sites/newsite/public/mod/book/notfound"
2025/06/05 07:00:29 [debug] 80884#0: *11 trying to use file: "/r.php" "/srv/sites/newsite/public/r.php"
2025/06/05 07:00:29 [debug] 80884#0: *11 internal redirect: "/r.php?"
< /code>
он пытается и (правильно) не находит файл, а затем он (правильно) возвращается в /р. Я думал об использовании серии испытаний IF вместо тестирования IF Спасибо
Подробнее здесь: https://stackoverflow.com/questions/796 ... -subfolder
Мобильная версия