Skip to content

Instantly share code, notes, and snippets.

@Rene-Roscher
Created July 30, 2023 02:19
Show Gist options
  • Select an option

  • Save Rene-Roscher/f802c64c0346271335c2e11743909f2f to your computer and use it in GitHub Desktop.

Select an option

Save Rene-Roscher/f802c64c0346271335c2e11743909f2f to your computer and use it in GitHub Desktop.
Laravel Cloudflare-Proxy
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
if (\App::environment('production')) {
$this->app['request']->server->set('HTTPS', true);
URL::forceScheme('https');
}
}
}
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylor@laravel.com>
*/
define('LARAVEL_START', microtime(true));
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$_SERVER['HTTP_X_FORWARDED_FOR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
<?php
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array|string|null
*/
protected $proxies = '*';
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment