# Display configuration at runtime?

**URL:** <https://www.ruby-forum.com/t/display-configuration-at-runtime/218938>\
**Category:** NGINX\
**Created:** [April 16, 2012, 11:15pm UTC](https://www.ruby-forum.com/t/display-configuration-at-runtime/218938 "2012-04-16T23:15:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [April 16, 2012, 11:15pm UTC](https://www.ruby-forum.com/t/display-configuration-at-runtime/218938/1 "2012-04-16T23:15:41Z")

</div>

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:

> **[Display configuration at runtime?](https://forum.nginx.org/read.php?2,225392,225392#msg-225392)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![michael\_teter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@michael\_teter](https://www.ruby-forum.com/u/michael_teter)\
**Post date:** [April 16, 2012, 11:39pm UTC](https://www.ruby-forum.com/t/display-configuration-at-runtime/218938/2 "2012-04-16T23:39:14Z")

</div>

Jim O.  
On Apr 16, 2012 5:15 PM, “michael\_teter” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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:  
> [http://forum.nginx.org/read.php?2,225392,225392#msg-225392](http://forum.nginx.org/read.php?2,225392,225392#msg-225392)

Jim

---

<div class="post-metadata">

**Author:** ![michael\_teter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@michael\_teter](https://www.ruby-forum.com/u/michael_teter)\
**Post date:** [April 17, 2012, 12:03am UTC](https://www.ruby-forum.com/t/display-configuration-at-runtime/218938/3 "2012-04-17T00:03:21Z")

</div>

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](http://www.ourname.com);  
rewrite ^(.\*) https://$server\_name$1 permanent;  
}  
server {  
listen 443;  
server\_name [www.ourname.com](http://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:

> **[Re: Display configuration at runtime?](https://forum.nginx.org/read.php?2,225392,225395#msg-225395)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![michael\_teter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@michael\_teter](https://www.ruby-forum.com/u/michael_teter)\
**Post date:** [April 17, 2012, 12:05am UTC](https://www.ruby-forum.com/t/display-configuration-at-runtime/218938/4 "2012-04-17T00:05:50Z")

</div>

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:

> **[Re: Display configuration at runtime?](https://forum.nginx.org/read.php?2,225392,225396#msg-225396)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![michael\_teter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@michael\_teter](https://www.ruby-forum.com/u/michael_teter)\
**Post date:** [April 17, 2012, 12:26am UTC](https://www.ruby-forum.com/t/display-configuration-at-runtime/218938/5 "2012-04-17T00:26:13Z")

</div>

On Apr 16, 2012 6:03 PM, “michael\_teter” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://nginx.org/en/docs/ngx_core_module.html#error_log).

> ```
> 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  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/IfIsEvil).

> ```
> 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:  
> [http://forum.nginx.org/read.php?2,225392,225395#msg-225395](http://forum.nginx.org/read.php?2,225392,225395#msg-225395)

Jim

---

<div class="post-metadata">

**Author:** ![michael\_teter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@michael\_teter](https://www.ruby-forum.com/u/michael_teter)\
**Post date:** [April 17, 2012, 1:06am UTC](https://www.ruby-forum.com/t/display-configuration-at-runtime/218938/6 "2012-04-17T01:06:22Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![michael\_teter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@michael\_teter](https://www.ruby-forum.com/u/michael_teter)\
**Post date:** [April 17, 2012, 12:18am UTC](https://www.ruby-forum.com/t/display-configuration-at-runtime/218938/7 "2012-04-17T00:18:48Z")

</div>

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:

> **[A debugging log](http://nginx.org/en/docs/debugging_log.html)**

wbr, Valentin V. Bartenev
