fideloper/proxy
Laravel trusted proxy middleware that correctly detects HTTPS, host, and client IP behind load balancers and reverse proxies by handling X-Forwarded-* headers. Fixes URL generation and request data when running behind ELB, Cloudflare, Nginx, etc.
http:// URLs generated on https:// sites).scheme/host.config/trustedproxies.php, enabling granular control over proxy validation.Request object (extends it to normalize headers).app/Http/Kernel.php).X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Host, reducing manual header management.trustedProxies configuration (default: empty array).['192.168.1.0/24']).X-Forwarded-For headers (e.g., client, proxy1, proxy2)?Request data (e.g., IP-based auth)? Conflicts may arise.trustedProxies config across environments.REMOTE_ADDR)?Request object, and configuration files. Integrates with:
url(), route(), and asset() helpers.Request::ip() and Request::userAgent() reflect the client, not proxies.TrustProxies middleware (if using older versions) or replaces it entirely.CF-Connecting-IP support via custom headers).X-Forwarded-* behavior.REMOTE_ADDR vs. X-Forwarded-For discrepancies.php artisan vendor:publish --provider="Fideloper\Proxy\ProxyServiceProvider".trustedProxies in config/trustedproxies.php:
'proxies' => [
'192.168.1.0/24', // Internal proxy subnet
'10.0.0.1', // Specific ELB IP
],
'headers' => [
'X-Forwarded-For',
'X-Forwarded-Host',
'X-Forwarded-Proto',
],
$middleware in app/Http/Kernel.php:
\Fideloper\Proxy\TrustProxies::class,
Request with proxied headers to validate Request::ip(), Request::getHost(), etc.http:// → https:// failures).Request::trustedProxy()) or fork the package.X-Forwarded-* headers. For non-standard headers (e.g., Cloudflare’s CF-Connecting-IP), extend the package or pre-process headers in middleware.Request data (e.g., laravel-debugbar, spatie/rate-limiter) will benefit but may need re-testing.spatie/activitylog (for accurate IP logging) and laravel/sanctum (for IP-based auth).trustedProxies and validate basic header parsing.url(), asset()) and HTTPS detection.trustedProxies).composer.json if using unsupported Laravel versions.Request behavior (e.g., "IPs are now client-facing").trustedProxies configuration for new environments.trustedProxies includes all intermediate proxies.X-Forwarded-Proto is correctly set to https.X-Forwarded-Host matches the app’s expected host.dd($request->header()).Request::getClientIp() vs. Request::ip() to compare behaviors.How can I help you explore Laravel packages today?