Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions public_html/static.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,33 @@
? $_SERVER['PATH_INFO']
: explode('static.php/', $_SERVER['REQUEST_URI'] ?? '')[1] ?? '';

$path = validateStaticFile($path);
$validated_path = validateStaticFile($path);

if (!$path) {
$real_path = realpath(INSTALL_PATH . $validated_path);

if (!$validated_path || !$real_path) {
http_response_code(404);
Comment thread
vortigont marked this conversation as resolved.
Resolved
exit;
}

serveStaticFile($path);

// Detect if web-server is Nginx with X-ACCEL config and let it do content delivery part
if (
!empty($_SERVER['SERVER_SOFTWARE']) &&
stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false &&
!empty($_SERVER['X-ACCEL_PREFIX'])
Comment thread
alecpl marked this conversation as resolved.
Resolved
) {
$accel_prefix = rtrim($_SERVER['X-ACCEL_PREFIX'], '/');

// let nginx take care about mime type
header("Content-Type: ");
header('X-Accel-Redirect: ' . $accel_prefix . '/' . $validated_path);
exit;
}


// server file's content via script
serveStaticFile($real_path);

/**
* Validate that the file exists and can be served
Expand Down Expand Up @@ -121,11 +140,6 @@ function validateStaticFile(string $path): ?string
return null;
}

$path = realpath(INSTALL_PATH . $path);

if ($path === false) {
return null;
}

return $path;
}
Expand Down