Hi! I've been encountering various silliness with Docker in terms of getting the true client IP on requests to Cloudflare -> Docker -> Caddy -> PHP-FPM -> Flarum.
I've tried a lot of things and spent a lot of time to make this work properly, but at this point I've basically given up.
So I've resorted to this strategy:
- Block all incoming requests to my server except from Cloudflare.
- In Caddy, write the True-Client-IP header with the value in Cf-Connecting-Ip. I really hate having a Cloudflare dependency in my code, but as I said above, I've given up on doing this properly.
- In /var/www/html/true-client-ip.php I have:
<?php
if (isset($_SERVER['HTTP_TRUE_CLIENT_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_TRUE_CLIENT_IP'];
}
- (I don't know why this is indented — bug?) In extend.php I have this:
<?php
require 'true-client-ip.php';
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Flarum\Extend;
return [
// Register extenders here to customize your forum!
];
I'm not fluent in PHP. Is this OK from a Flarum standpoint? It certainly seems to work.
Thank you!