monicahq/laravel-cloudflare
Composer 安装命令:
composer require monicahq/laravel-cloudflare
包简介
Add Cloudflare ip addresses to trusted proxies for Laravel.
关键字:
README 文档
README
Add Cloudflare ip addresses to trusted proxies for Laravel.
Installation
- Install package using composer:
composer require monicahq/laravel-cloudflare
- Configure Middleware
Replace TrustProxies middleware in your bootstrap/app.php file:
->withMiddleware(function (Middleware $middleware) { $middleware->replace( \Illuminate\Http\Middleware\TrustProxies::class, \Monicahq\Cloudflare\Http\Middleware\TrustProxies::class ); })
Custom proxies callback
You can define your own proxies callback by calling the LaravelCloudflare::getProxiesUsing() to change the behavior of the LaravelCloudflare::getProxies() method.
This method should typically be called in the boot method of your AppServiceProvider class:
use Illuminate\Support\ServiceProvider; use Monicahq\Cloudflare\LaravelCloudflare; use Monicahq\Cloudflare\Facades\CloudflareProxies; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. */ public function boot(): void { LaravelCloudflare::getProxiesUsing(fn() => CloudflareProxies::load()); } }
How it works
The middleware uses Illuminate\Http\Middleware\TrustProxies as a backend.
When the cloudflare ips are detected, they are used as trusted proxies.
Refreshing the Cache
This package retrieves Cloudflare's IP blocks, and stores them in cache. When request comes, the middleware will get Cloudflare's IP blocks from cache, and load them as trusted proxies.
You'll need to refresh the cloudflare cache regularely to always have up to date proxy.
Use the cloudflare:reload artisan command to refresh the IP blocks:
php artisan cloudflare:reload
Suggestion: add the reload command in the schedule
Add a schedule to your routes/console.php file to refresh the cache, for instance:
use Illuminate\Support\Facades\Schedule; Schedule::command('cloudflare:reload')->daily();
View current Cloudflare's IP blocks
You can use the cloudflare:view artisan command to see the cached IP blocks:
php artisan cloudflare:view
Option: publish the package config file
If you want, you can publish the package config file to config/laravelcloudflare.php:
php artisan vendor:publish --provider="Monicahq\Cloudflare\TrustedProxyServiceProvider"
This file contains some configurations, but you may not need to change them normally.
Running tests for your package
When running tests for your package, you generally don't need to get Cloudflare's proxy addresses.
You can deactivate the Laravel Cloudflare middleware by adding the following environment variable in
your .env or phpunit.xml file:
LARAVEL_CLOUDFLARE_ENABLED=false
Compatibility
| Laravel | monicahq/laravel-cloudflare |
|---|---|
| 5.x-6.x | <= 1.8 |
| 7.x-8.53 | 2.x |
| 8.54-12.0 | 3.x |
| >= 11.0 | >= 4.x |
Citations
This package was inspired by lukasz-adamski/laravel-cloudflare and forked from ogunkarakus/laravel-cloudflare.
License
Author: Alexis Saettler
This project is part of MonicaHQ.
Copyright © 2019–2025.
Licensed under the MIT License. View license.
monicahq/laravel-cloudflare 适用场景与选型建议
monicahq/laravel-cloudflare 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.97M 次下载、GitHub Stars 达 340, 最近一次更新时间为 2018 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「cloudflare」 「proxies」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 monicahq/laravel-cloudflare 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 monicahq/laravel-cloudflare 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 monicahq/laravel-cloudflare 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle for Cloudflare integration: trusted proxies, real client IP detection, forwarded headers.
Cloudflare Middleware For Guzzle
Library for helping bypass the Cloudflare IUAM page
A ZF2 plugin to fix global variables when using CloudFlare
Boost the performance of your site with Cloudflare or Varnish.
Alfabank REST API integration
统计信息
- 总下载量: 2.97M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 340
- 点击次数: 35
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-05