# Forced 404 without a location display?

**URL:** <https://www.ruby-forum.com/t/forced-404-without-a-location-display/244930>\
**Category:** NGINX\
**Created:** [July 11, 2016, 9:26pm UTC](https://www.ruby-forum.com/t/forced-404-without-a-location-display/244930 "2016-07-11T21:26:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [July 11, 2016, 9:26pm UTC](https://www.ruby-forum.com/t/forced-404-without-a-location-display/244930/1 "2016-07-11T21:26:59Z")

</div>

I have some servers where I use an old method of gating a path by using  
a file check.

this allows staff to turn off certain locations during  
migrations/updates without having root privileges (needed to restart  
nginx)

an issue I noticed this method now (perhaps always) shows the name of  
the location on the default 404 template [the response that nginx  
generates via code, not a template on the fs]

Does anyone know how to disable showing the location without defining a  
custom template on the filesystem? or perhaps someone can think of a  
better way to accomplish my goals?

location /paths/to/ {  
if (!-f /etc/nginx/\_flags/is\_running) {  
rewrite ^.\*$ @is\_running break;  
}  
}  
location = @is\_running {  
return 404;  
}

=======  
that generates this

 404 Not Found 
# 404 Not Found
 The resource could not be found.  
  
 /@is\_running

---

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [July 11, 2016, 10:25pm UTC](https://www.ruby-forum.com/t/forced-404-without-a-location-display/244930/2 "2016-07-11T22:25:59Z")

</div>

On Mon, Jul 11, 2016 at 03:26:30PM -0400, Jonathan V. wrote:

> location /paths/to/ {

# ============================================= location /paths/to/ { if ( !-f /etc/nginx/\_flags/is\_running ) { rewrite ^ /is\_running last; } } location = /is\_running { internal; return 404 ‘nothing\n’; }

Does it work for you?

–  
Cheers,  
Oleg A. Mamontov

mailto: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

skype: lonerr11  
cell: +7 (903) 798-1352

---

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [July 11, 2016, 10:28pm UTC](https://www.ruby-forum.com/t/forced-404-without-a-location-display/244930/3 "2016-07-11T22:28:19Z")

</div>

Hello!

On Mon, Jul 11, 2016 at 03:26:30PM -0400, Jonathan V. wrote:

> }  
> 404 Not Found
> 
> # 404 Not Found
> The resource could not be found.  
>   
> /@is\_running

This is not something nginx generates.  
An nginx-generated error will look like:

404 Not Found
# 404 Not Found

* * *
nginx/1.11.3

No location information is added by nginx to error pages, and  
never was. You are probably using something with 3rd party  
patches. An obvious fix is to switch to using vanilla nginx  
instead, it can be downloaded here:

> **[nginx: download](http://nginx.org/en/download.html)**

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [July 13, 2016, 12:46am UTC](https://www.ruby-forum.com/t/forced-404-without-a-location-display/244930/4 "2016-07-13T00:46:08Z")

</div>

On Jul 11, 2016, at 4:27 PM, Maxim D. wrote:

> No location information is added by nginx to error pages, and  
> never was. You are probably using something with 3rd party  
> patches. An obvious fix is to switch to using vanilla nginx  
> instead, it can be downloaded here:

On Jul 11, 2016, at 4:25 PM, Oleg A. Mamontov wrote:

> =============================================  
> Thanks to you both!

I spent way more time than I should tracking the issue. I finally  
figured it out. Details below:

1. I am using a non-standard nginx – I run openresty. I thought this  
might have been the issue so started creating test-cases to pin down,  
and running against all the nginx & openresty versions. I could not  
consistently get this to repeat.

2. The first part of the problem is that I had `break` on my rewrite,  
instead of `last`.

3. The second part of my problem, and this is where the confusion  
happened – a proxypass was involved

Using `last`:  
what i wanted happened

Using `break`  
the rewrite to `/is_running` got passed to the proxypass; the  
application was creating the error message  
the app’s error message template was very similar to nginx – and that  
threw me off  
i only figured this out, because nginx served an error when the  
application was taken offline during an update
