Display configuration at runtime?

Howdy.

I’m working on setting up a maintenance page, and I can’t figure out
where Nginx is looking for the maintenance.html that I have specified.
I’ve tried placing the file in a lot of different locations, but I still
get the generic “503 Service Temporarily Unavailable” page.

My question is, is there a way I can get Nginx to display it’s
configuration at run-time, so perhaps I can determine where it is
looking for the file?

Thanks in advance,
Michael

Posted at Nginx Forum:

Jim O.
On Apr 16, 2012 5:15 PM, “michael_teter” [email protected] wrote:

Howdy.

I’m working on setting up a maintenance page, and I can’t figure out
where Nginx is looking for the maintenance.html that I have specified.
I’ve tried placing the file in a lot of different locations, but I still
get the generic “503 Service Temporarily Unavailable” page.

What does the error log show?

If you use something like:

location / {
root /some/path;
try_files maintenance.html $uri $uri/;
…;
}

then nginx will look for maintenance.html in the root directory and
serve
it if it’s present.

So to put our sites into maintenance mode, we simply copy our
maintenance.html into the root directory. No need to reload nginx. When
we’re ready to go back up, the file is removed.

My question is, is there a way I can get Nginx to display it’s
configuration at run-time, so perhaps I can determine where it is
looking for the file?

Thanks in advance,
Michael

Posted at Nginx Forum:
Display configuration at runtime?

Jim

Thanks for the quick response. My error log shows nothing, but my
access log does show the visit.

Here’s the relevant part of my config:

server {
listen 80;
server_name www.ourname.com;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443;
server_name www.ourname.com;
#try_files $uri /maintenance.html @passenger;
root /home/michael/ourname/public;

  # MT added 20120416
  error_page 503 /maintenance.html;
  if (-f $document_root/../tmp/stop.txt) {
    set $maintenance 1;
  }

  if ($maintenance) {
    return 503;
  }

  passenger_enabled on;
  #rails_env development;
  rails_env production;
  location @passenger {
    passenger_enabled on;
    root /home/michael/ourname/public;
  }

  ssl on;
  ssl_certificate /home/michael/ssl_keys/ourname.com_ssl.crt;
  ssl_certificate_key /home/michael/ssl_keys/Cert1.key;
  #return 403;

}

Posted at Nginx Forum:

I should note that on this line:

error_page 503 /maintenance.html;

I have tried a variety of paths.
/maintenance.html
$document_root/maintenance.html
/some/other/path/maintenance.html

etc.

I don’t understand how Nginx can see the stop.txt that I use to put it
in maint mode, but it can’t see (or ignores)
$document_root/maintenance.html (when I had that set as the error_page)

Posted at Nginx Forum:

On Apr 16, 2012 6:03 PM, “michael_teter” [email protected] wrote:

Thanks for the quick response. My error log shows nothing, but my
access log does show the visit.

Use higher level error logging. See
Core functionality.

 listen 443;
 server_name www.ourname.com;
 #try_files $uri /maintenance.html @passenger;

Why are you not using this line? It’s the perfect use case for
“try_files”.
Note that I believe that you should remove the leading “/” from
“/maintenance.html”.

 }

This is a lot more work than using the above “try_files”. See also
If is Evil… when used in location context | NGINX.

 ssl_certificate /home/michael/ssl_keys/ourname.com_ssl.crt;
 ssl_certificate_key /home/michael/ssl_keys/Cert1.key;
 #return 403;

}

Posted at Nginx Forum:
Re: Display configuration at runtime?

Jim

On Mon, Apr 16, 2012 at 06:02:45PM -0400, michael_teter wrote:

Hi there,

My error log shows nothing, but my
access log does show the visit.

The error log doesn’t seem immediately useful in this case; but with
the debug log you can work out what is happening.

The short answer is “internal redirect”, or “subrequest”.

Here’s the relevant part of my config:

  error_page 503 /maintenance.html;
  if (-f $document_root/../tmp/stop.txt) {
    set $maintenance 1;
  }

  if ($maintenance) {
    return 503;
  }

For any request, if the file exists then return 503, which does an
internal redirect to /maintenance.html. This subrequest goes through the
same process, and since the file still exists, you would end up in a
loop.

With the following config, you can break out of the loop:

    error_page 503 /maintenance.html;
    if ($uri = "/maintenance.html") {
        break;
    }
    if (-f $document_root/../tmp/stop.txt) {
        return 503;
    }

Although I confess I don’t know if there is a “best” way to implement
a 503 response to all requests in nginx based on the existence of a
flag file.

f

Francis D. [email protected]

On Tuesday 17 April 2012 01:15:17 michael_teter wrote:
[…]

My question is, is there a way I can get Nginx to display it’s
configuration at run-time, so perhaps I can determine where it is
looking for the file?

Debug log will help:
http://nginx.org/en/docs/debugging_log.html

wbr, Valentin V. Bartenev