2

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.
David Eisenstat
  • 64,237
  • 7
  • 60
  • 120
Victordb
  • 519
  • 1
  • 11
  • 25
  • 2
    I have never tested this on remote website. But As I see [it should](https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php#L51) You can add a dummy route to verify your IP: `Route::get('/what-is-my-ip', function(){ return request()->ip();});` and verify you're allowing the correct IP address – Clément Baconnier Feb 19 '19 at 10:20
  • You are right, I did as you said and for some reason it shows another ip than what google `show my ip` shows. I am using cloudflare on the vps could that be a reason? If you post your comment as an answer I will vote it correct. Do you have any ideea why is the ip different? Thank you! – Victordb Feb 19 '19 at 11:01
  • 1
    In my experience, IP services aren't that smart.. Some of them show (what I think is) my provider IP. I am on Ubuntu did and did an alias `myip='curl https://ipinfo.io/ip'` I know that this own is correct. – Clément Baconnier Feb 19 '19 at 11:07
  • `https://ipinfo.io/ip` shows me the same ip google does. But for some reason my vps `Route::get('/what-is-my-ip', function(){ return request()->ip();});` shows another ip. If I use that in maintenance mode it works but is very wierd that is shows a completely different ip than any other `show my ip` sites. – Victordb Feb 19 '19 at 11:15
  • Weird indeed. Just be sure that Laravel doesn't see the same IP for everyone. If you'are behind cloudflare, I believe it will returns you the couldflare IP instead of the user IP. https://laracasts.com/discuss/channels/laravel/cloudflare-and-user-ip – Clément Baconnier Feb 19 '19 at 11:28

1 Answers1

8

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

Clément Baconnier
  • 5,718
  • 5
  • 29
  • 55
  • 2
    Just be careful blindly trusting anybody who sets the `HTTP_CF_CONNECTING_IP` header. You may want to look into Laravel's truster proxies options. – GGGforce Jan 28 '20 at 22:36