# Maintenance page and localhost access

**URL:** <https://www.ruby-forum.com/t/maintenance-page-and-localhost-access/189019>\
**Category:** NGINX\
**Created:** [May 22, 2010, 1:32am UTC](https://www.ruby-forum.com/t/maintenance-page-and-localhost-access/189019 "2010-05-22T01:32:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_MSEvans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7bcc69/32.png) [@Ian\_MSEvans](https://www.ruby-forum.com/u/Ian_MSEvans)\
**Post date:** [May 22, 2010, 1:32am UTC](https://www.ruby-forum.com/t/maintenance-page-and-localhost-access/189019/1 "2010-05-22T01:32:21Z")

</div>

As I prepare to test some changes related to the “0day exploit” thread,  
I thought I’d set up a maintenance page block so I could do the testing.

Just realized though that the maintenance block examples take the site  
down for everyone.

How do you serve the maintenance page to visitors will still allowing  
localhost access.

Should I just create a new server block listening on another port and  
deny all, allow 127.0.0.1?

---

<div class="post-metadata">

**Author:** ![Ian\_MSEvans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7bcc69/32.png) [@Ian\_MSEvans](https://www.ruby-forum.com/u/Ian_MSEvans)\
**Post date:** [May 27, 2010, 9:55pm UTC](https://www.ruby-forum.com/t/maintenance-page-and-localhost-access/189019/2 "2010-05-27T21:55:06Z")

</div>

Use the $remote\_addr variable to check against the local IP address, if  
the  
visitor isn’t local, then send a 503 maintenance page. The 503 code is  
important so search engines wont mark the website as dead.

---

<div class="post-metadata">

**Author:** ![Ian\_MSEvans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7bcc69/32.png) [@Ian\_MSEvans](https://www.ruby-forum.com/u/Ian_MSEvans)\
**Post date:** [May 28, 2010, 8:41pm UTC](https://www.ruby-forum.com/t/maintenance-page-and-localhost-access/189019/3 "2010-05-28T20:41:54Z")

</div>

Ian M. Evans wrote:

> Should I just create a new server block listening on another port and  
> deny all, allow 127.0.0.1?
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)  
> You could just do it like this in the global section:

```
geo $maintenance {
            default 0;
            80.15x.yy.zz/29 0; # your IPs still allowed
            80.15x.yy.zz/29 0; # another bunch of allowed IPs
}

```

and in the server section add this:

```
if ($maintenance) {
   rewrite ^(.*)$ /yourmaintenancefile.html last;
}

```

When you want to start maintenance just switch the “default 0;” to  
“default 1;” in the $maintenance block and reload your nginx.

Have a look at [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpGeoModule)

## HTH, Emil Krüper

> **[Website under maintenance](https://uruz.org/)**
