Going to deploy a new release to our server. After this deployment, we need to manually change some settings for users, and preform some testing.

We need our site run as normal, so we can do our job, but not allow customers to access before we finish.

We use Capistrano for deployment. So lets add official maintenance gem for this. This gem will create/remove a maintenance file on server by command line. We just need to config Nginx to check if the maintenance file exist, and not accessing from office IP address. If so then return error 503 with maintenance message.

error_page 503 @503; 

# maintenance page exists? 
if (-f /path/to/project/shared/public/system/maintenance.html) {  
  set $maintenance M; 
} 

# office IP? 
if ($remote_addr = "1.2.3.4") {  
  set $maintenance "${maintenance}O"; 
} 

# Return a 503 error if the maintenance page exists and not access from office IP address. 
if ($maintenance = M) {  
  return 503; 
} 

location @503 {  
  # Serve static assets if found. 
  if (-f $request_filename) { 
    break; 
  } 

  # Set root to the shared directory. 
  root /path/to/project/shared/public; 
  rewrite ^(.*)$ /system/maintenance.html break; 
} 

... other config ... 

References: