Forum: NGINX how can i quickly handle alternate config for site downtime?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3fc448a0368821b51a9f7e2781a8b7a6?d=identicon&s=25 Jonathan Vanasco (Guest)
on 2008-12-26 22:01
(Received via mailing list)
for the pat few years, i have stuff like this:

file:  /_hosts/findmeon_
content:
  include /_hosts/findmeon_/www.findmeon.com ;
  #include /_hosts/findmeon_/www.findmeon.com-downtime ;

when i want to take a domain up/down, i just toggle to comment line
for the include, and restart nginx like magic.

i'm wondering if there is a better way?

ideally i'd like to be able to either have some sort of if/else logic
in nginx , and maybe either a command-line or file based way (this
way kill -HUP still works )

or maybe someone else has a better method ?
A86224d72ce21cd9f5bee6784d4b06c7?d=identicon&s=25 Corey Donohoe (atmos)
on 2008-12-26 23:17
(Received via mailing list)
On Fri, Dec 26, 2008 at 1:49 PM, Jonathan Vanasco <nginx@2xlp.com>
wrote:
> for the pat few years, i have stuff like this:
>
> file:  /_hosts/findmeon_
> content:
>        include /_hosts/findmeon_/www.findmeon.com ;
>        #include /_hosts/findmeon_/www.findmeon.com-downtime ;

Is this other config file pointing tosome kind of status page that
says "findmeon.com is down right now!" or something similar?  If it
is, you prolly wanna investigate maintenance pages and have them
return 503s during the downtime.

http://www.ruby-forum.com/topic/141251
3fc448a0368821b51a9f7e2781a8b7a6?d=identicon&s=25 Jonathan Vanasco (Guest)
on 2008-12-28 18:54
(Received via mailing list)
On Dec 26, 2008, at 4:59 PM, Corey Donohoe wrote:

> Is this other config file pointing tosome kind of status page that
> says "findmeon.com is down right now!" or something similar?  If it
> is, you prolly wanna investigate maintenance pages and have them
> return 503s during the downtime.
>
> http://www.ruby-forum.com/topic/141251

hmm....  that could work.

would you be able to share those 2 snippets you listed as a pastie
again ?  they expired ( as did your old link at http://
forum.engineyard.com/forums/3/topics/22 )

also - just to be sure about this... you're triggering a downtime
response just by a file-existence check, right?
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2008-12-28 21:08
(Received via mailing list)
On Dec 28, 2008, at 9:23 AM, Jonathan Vanasco wrote:

> hmm....  that could work.
>
> would you be able to share those 2 snippets you listed as a pastie
> again ?  they expired ( as did your old link at 
http://forum.engineyard.com/forums/3/topics/22
>  )
>
> also - just to be sure about this... you're triggering a downtime
> response just by a file-existence check, right?
>


Jonathan-

  Yeah we are triggering a maintenance page via the existance of a
file. Here is how it looks in the config file.

# Rewrite all the requests to the maintenance.html page if it exists.
if (-f $document_root/system/maintenance.html) {
   return 503;
}


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


  This means that if $document_root/system/maintenance.html exists,
then only serve that file and nothing else for every request.

Cheers-
Ezra Zygmuntowicz
ez@engineyard.com
3fc448a0368821b51a9f7e2781a8b7a6?d=identicon&s=25 Jonathan Vanasco (Guest)
on 2009-01-06 20:46
(Received via mailing list)
On Dec 28, 2008, at 2:58 PM, Ezra Zygmuntowicz wrote:
> Jonathan-
>
>   Yeah we are triggering a maintenance page via the existance of a
> file. Here is how it looks in the config file.

that's a really elegant solution , using semaphores.

reminds me of some not-so-dirty hacks in modperl ;)
3fc448a0368821b51a9f7e2781a8b7a6?d=identicon&s=25 Jonathan Vanasco (Guest)
on 2009-01-07 00:07
(Received via mailing list)
On Dec 28, 2008, at 2:58 PM, Ezra Zygmuntowicz wrote:
> error_page 503 @503;
> location @503 {
>   rewrite  ^(.*)$  /system/maintenance.html break;
> }


forgive my constant questions on this...

can you explain the @ ?

its not in the docs anywhere.

a friend thinks it might be a namespace that you know you aren't using.

just trying to figure this out, as I can't seem to trigger the custom
error and i think that might be part of it.
561c2fb6d0c72e0c7bc52b263c7d56c3?d=identicon&s=25 Merlin (Guest)
on 2009-01-07 00:49
(Received via mailing list)
Yes, it sets up a location that you are most likely never going to use.
It
appears to be convention within nginx configurations.  I don't know when
it
started, but I've seen it on this list for some time now.  I am pretty
sure
that you could use other special characters if you wanted, too, it's
just a
character to nginx.
A460d05ba391146671c2a4de2433a014?d=identicon&s=25 Igor Clark (igorclark)
on 2009-01-07 18:41
Merlin wrote:

> Yes, it sets up a location that you are most likely never going to use.
> It appears to be convention within nginx configurations.  I don't know
> when it started, but I've seen it on this list for some time now.  I am
> pretty sure that you could use other special characters if you wanted,
> too, it's just a character to nginx.

Igor S refers to these as "named locations". A common use is e.g.

    location / {
        error_page 404 = @myapp;
    }

    location @myapp {
        fastcgi_index blah;
        fastcgi_param ...;
    }

so that any URLs that would normally go through rewrite stages like

    if (! -e $uri) {
        rewrite ....;
    }

are automatically routed to the appropriate back-end.

In release 0.7.27 Igor S added the try_files directive which works
similarly but adds a list of filesystem locations to try before hitting
a named location as default, and only logs errors in case of total
failure (as I understand it):

        location / {
                try_files $uri $uri/index.html @myapp;
        }


I haven't seen any characters other than @ used to notate named
locations, but I'm sure Igor S will be able to elucidate.

Cheers,
Igor
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-15 15:17
(Received via mailing list)
On Wed, Jan 07, 2009 at 06:41:54PM +0100, Igor Clark wrote:

>     location / {
>     if (! -e $uri) {
>         location / {
>                 try_files $uri $uri/index.html @myapp;
>         }
>

The errors will not be logged at all. On total failure nginx will do
internal redirect to last parameter (@myapp in this case).

> I haven't seen any characters other than @ used to notate named
> locations, but I'm sure Igor S will be able to elucidate.

The "@" is speacial symbol to indicate "named location".
The "named locations" are used in error_page redirection to preserve
URI.
This topic is locked and can not be replied to.