Search code examples
laravellaravel-artisanlaravel-5.7maintenance-mode

Laravel maintenance mode --allow ip not working


I am trying to allow my public internet ip through maintenance mode in laravel on a vps.

Does the --allow command works over internet or does it work only on the localhost? Because I cannot get pass the maintenance mode page with the following command:

$ php artisan down --allow=xx.xx.xx.xx (my public internet ip)
Application is now in maintenance mode.
$ php artisan up
Application is now live.

Solution

  • You can verify the IP address your application see and allow it:

    Route::get('/what-is-my-ip', function(){ 
        return request()->ip();
    });
    

    But be careful, if you're behind a content delivery network service, like cloudflare, you will see the IP of the service instead of the user. Which mean, everyone will have the same IP.

    With e.g. Cloudflare, you can make it works by re-setting the correct user IP in public/index.php

    <?php
    
    if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
    }
    

    source with more explanations: https://laracasts.com/discuss/channels/laravel/cloudflare-and-user-ip