jackbrycesmith / laravel-caprover-template

Template to deploy a Laravel app in docker for CapRover
MIT License
127 stars 44 forks source link

Get real ip and host in application #24

Closed elvinkim03 closed 3 months ago

elvinkim03 commented 3 months ago

Nice template btw ! I'm facing issue with getting client real IP and host whenever i called $request->getHost() or $request->ip() cause it always return local ip. What should I do and sorry I'm not familiar with caddy

jackbrycesmith commented 3 months ago

👍 Hey thanks it's been a while since I've used this template, but I think this is something you can configure on the laravel side.

I had the following on a laravel 10 project to get the correct ip to come through: https://laravel.com/docs/10.x/requests#configuring-trusted-proxies

    /**
     * The trusted proxies for this application.
     *
     * @var array|string
     */
    protected $proxies = [
        '10.0.0.0/8',
        '127.0.0.1',
        '172.16.0.0/12',
        '192.168.0.0/16',
    ];

Looks like they've slightly changed how it's configured in Laravel 11 (https://laravel.com/docs/11.x/requests#configuring-trusted-proxies) but this is where I would look into first.

elvinkim03 commented 3 months ago

It's working now. Thanks man, appreciate it