Testing prefix forwarding configs to fix livewire upload bug

This commit is contained in:
Asa Yee 2025-12-15 10:01:45 -04:00
parent 82bb4969b8
commit 1670da55e9
3 changed files with 58 additions and 1 deletions

View file

@ -0,0 +1,35 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class ApplyForwardedPrefix
{
public function handle(Request $request, Closure $next)
{
$prefix = "/hosp";
if ($prefix) {
// Normalize prefix to "/hosp" (no trailing slash)
$prefix = '/' . ltrim($prefix, '/');
$prefix = rtrim($prefix, '/');
// If Apache stripped /hosp before proxying, Laravel sees "/livewire/..."
// Re-inject the prefix into REQUEST_URI so URL generation/signing aligns with the browser URL.
$uri = $request->server->get('REQUEST_URI'); // includes query string
if (is_string($uri) && $uri !== '' && !str_starts_with($uri, $prefix . '/')) {
$request->server->set('REQUEST_URI', $prefix . $uri);
}
// Help Symfony compute the base URL.
$scriptName = $request->server->get('SCRIPT_NAME') ?: '';
if ($scriptName !== '' && !str_starts_with($scriptName, $prefix . '/')) {
$request->server->set('SCRIPT_NAME', $prefix . $scriptName);
}
}
return $next($request);
}
}

View file

@ -3,6 +3,7 @@
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
@ -12,7 +13,13 @@
)
->withMiddleware(function (Middleware $middleware) {
//
$middleware->trustProxies(at: '172.16.121.9');
$middleware->trustProxies(
at: '*', // or ['127.0.0.1', '::1'] / your proxy IP(s)
headers: Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO
);;
})
->withExceptions(function (Exceptions $exceptions): void {
//

15
hosp.conf Normal file
View file

@ -0,0 +1,15 @@
Listen 25120
<VirtualHost 127.0.0.1:25120>
ServerName jedi.msya.gov.tt
DocumentRoot /var/www/html/hosp_2025/public
<Directory /var/www/html/hosp_2025/public>
AllowOverride All
Require all granted
Options FollowSymLinks
</Directory>
ErrorLog /var/log/httpd/hosp_2025_error.log
CustomLog /var/log/httpd/hosp_2025_access.log combined
</VirtualHost>