önce statik sayfa hizmet etmek, ancak dosya eksikse, o bir PHP dosyası yerine yükleyeceğini ve PHP içeriği ele olmalıdır.Nginx ben nginx ile statik HTML dosyaları hizmet etmek istiyorum
try_files
'un çeşitli kombinasyonlarını test ediyorum, ancak kafamı alamıyorum. olmalıdır her sayfaya tarama
<?php
$path = $_SERVER['REQUEST_URI'];
$pattern = '/^\/(.*)\.html$/';
$matches = [];
$results = preg_match($pattern, $path, $matches);
if (count($matches) > 0) {
if ($matches[1] == "dynamic") {
require 'dynamic.php';
} else {
echo "Not found!";
}
} else {
echo "Index page!";
}
sonuçları:
./
../
dynamic.php
index.php
static/
static/static.html
Sonra böyle endeksi küçük bir PHP kodu var: Ben şöyle bir kukla PHP uygulaması var
server {
listen 80;
server_name .foo.bar *.foo.bar;
access_log /var/log/nginx/foo.access.log;
error_log /var/log/nginx/foo.error.log;
root /var/www/foo;
index index.php;
location/{
# Trying with 'try_files' here. No success.
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm-foo.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
0123:
Bu
http://foo.bar/ - Loads index.php
http://foo.bar/static.html - Loads static/static.html
http://foo.bar/dynamic.html - Loads index.php & PHP requires dynamic.php
http://foo.bar/baz.html - Loads index.php with "not found" message
Ben nginx yapılandırma dosyasında ne var
Ben defalarca çalışıyor ve besbelli tamamen bu hat ile başarısız oldum:
try_files $uri $uri/static /index.php;
ben eksik bir şey. Yardım et?
senin durumunda yeniden yazma bazı URL yapmak ama PHP sürekli kullanılarak görüntülenir sayfasını işlemek mümkün değil midir? – AntoineB