Maintenance mode for all but my ip

Getting ready to convert the site to UTF-8 (finally!) and wanted to
know how I could issue error code 503 to all people and bots but still
allow my IP in so I can go 'round the site checking for glitches due to
the change.

Right now I have this implementation for 503’s but that issues the
error code for everyone including me. I know about allow/deny but I’m
not sure how it fits into this mechanism.

if (-f $document_root/maintenance.html) {
return 503;
}

error_page 503 @503;
location @503 {
rewrite ^(.*)$ /maintenance.html break;
}

I am new to the use of maps, but I suppose it would fit perfectly, using
core variables such as the binary IP address:
Maybe something like:

server {
error_page 503 /503.html # Configuring error page

map $binary_remote_addr $target { # Configuring white-listed IP

addresses
default KO
your_whitelisted_binary_IP_address_value OK
}

rewrite ^.*$ $target #Redirecting all traffic according to 

map-assigned
value

location @OK { # Named location to do nothing, i.e. serve content as

usual
}

location @KO { # Named location to trap maintenance traffic, 

spawning a
HTTP 503 error
return 503;
}
}

Untested, thus unsure, but I’d seek something looking like this.

B. R.

On 7 December 2013 14:58, B.R. [email protected] wrote:

I am new to the use of maps, but I suppose it would fit perfectly, using
core variables such as the binary IP address:
[snip]
rewrite ^.*$ $target #Redirecting all traffic according to map-assigned

I don’t particularly like ^^^ this. It seems like a level of
indirection too far :wink:

Using /almost/ the same technique, you could have a map based on the
remote IP like BR suggested, but use it like this:

http {
map $remote_addr $not_me {
default 1;
my.ip.address “”;
}
server {

whatever else you need

location / {
if ($not_me) {
return 503
}
}
}
}

Cheers,
Jonathan

Hello,

On Sat, Dec 7, 2013 at 4:10 PM, Jonathan M.
[email protected]wrote:

rewrite ^.*$ $target #Redirecting all traffic according to

map-assigned

I don’t particularly like ^^^ this. It seems like a level of
indirection too far :wink:

​To me​, your solution looks double evil:
1°) Using an unneeded ‘if’ directive
2°) Needs modifying each and every location block.
Going that way, you could use the much simpler Paul’s solution, denying
all
blocks to everyone but the allowed IP address, that is copy-pasting
‘deny’
and ‘allow’ directives​ everywhere…

I was trying to think about something more scalable, self-contained and
generic. ;o)

B. R.

On 2013-12-07 09:58, B.R. wrote:

default

location @KO { # Named location to trap maintenance traffic,

spawning a HTTP 503 error
return 503;
}
}

Untested, thus unsure, but Id seek something looking like this.

Thanks. I’ll give this a spin. Is there anyway to still trigger the
mapping based on the existence of a maintenance.whatever file? Just
thinking of the ease of quickly touch’ing the maintenance file to
trigger the mapping as opposed to fiddling with the conf and reloading
each time you want to do some quick testing.

On 2013-12-07 15:31, B.R. wrote:

By giving it 30 seconds of intensive thinking, I am sure you could
figure this out by yourself, considering you already provided the if
(-f ***) {…} trick.

Since the
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if [2]if
directive works in server blocks, you could enclose the rewrite rule
in it to only apply maintenance mode based on the presence (or the
absence?) of a specific file.

Sorry…too many late nights during this migration/upgrade. So I can
just place the “rewrite ^.*$ $target” into my ‘if’. I’ll give it a whirl
as soon as I get some caffeine. :slight_smile:

​Hello,​

On Sat, Dec 7, 2013 at 6:31 PM, Ian E. [email protected]
wrote:

Thanks. I’ll give this a spin. Is there anyway to still trigger the
mapping based on the existence of a maintenance.whatever file? Just
thinking of the ease of quickly touch’ing the maintenance file to trigger
the mapping as opposed to fiddling with the conf and reloading each time
you want to do some quick testing.

By giving it 30 seconds of intensive thinking, I am sure you could
figure
this out by yourself, considering you already provided the if (-f ***)
{…} trick.

Since the
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if’if’
directive works in server blocks, you could enclose the rewrite rule in
it
to only apply ‘maintenance mode’ based on the presence (or the absence?)
of
a specific file.

Please come back to tell us if it worked as intended/expected… or what
had to be corrected/added! :o)​


B. R.

Full working config;
http://www.cyberciti.biz/faq/custom-nginx-maintenance-page-with-http503/

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,245306,245316#msg-245316

On 7 December 2013 15:19, B.R. [email protected] wrote:

indirection too far :wink:

To me, your solution looks double evil:
1°) Using an unneeded ‘if’ directive

Using “if” is absolutely fine if all you’re doing is issuing a return
directly from it. It’s only when you try to do things /after/ an “if”
successfully matches that it’s considered evil …

2°) Needs modifying each and every location block.

I didn’t really pay attention to the scoping of the return. Moving the
return to the most appropriate place in the config shouldn’t be too
tricky for the OP to figure out …

I was trying to think about something more scalable, self-contained and
generic. ;o)

What I suggested would work, AFAICT, with a single map, and a
per-server{} “if($not_me){return 503;}”. That’s hardly onerous, I’d
say …

YMMV,
Jonathan

On Sat, Dec 7, 2013 at 10:39 PM, itpp2012 [email protected] wrote:

Full working config;
http://www.cyberciti.biz/faq/custom-nginx-maintenance-page-with-http503/

​Thanks for replying after having carefully read ​what is asked for by
Ian
and not giving a too quick answer copy-pasted from Google

B. R.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs