# Using "if -f" to return 503 for maintenace: good or bad?

**URL:** <https://www.ruby-forum.com/t/using-if-f-to-return-503-for-maintenace-good-or-bad/221451>\
**Category:** NGINX\
**Created:** [July 16, 2012, 1:42am UTC](https://www.ruby-forum.com/t/using-if-f-to-return-503-for-maintenace-good-or-bad/221451 "2012-07-16T01:42:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 16, 2012, 1:42am UTC](https://www.ruby-forum.com/t/using-if-f-to-return-503-for-maintenace-good-or-bad/221451/1 "2012-07-16T01:42:42Z")

</div>

Hello,

Sometimes I need to regenerate my website. I do not want my users to see  
semi-generated site. I also do not want google to see 404 errors.

The best solution is to return “503” for while I my system generates new  
files. Is not it?

So I want my system to put special “lock” file before generating content  
and to remove it after it.

And I put onto my server config:

if (-f $document\_root/lock ) {  
return 503;  
}

Is my solution OK or is it bad? If so, what is the best solution?  
Probably I can configure nginx to establish TCP connection to my system  
(permanent connection) and to show 503 in case of connection is  
unavailable?  
That should be better because we would not need to check filesystem each  
time.

Thanks!

Posted at Nginx Forum:

> **[Using "if -f" to return 503 for maintenace: good or bad?](https://forum.nginx.org/read.php?2,228604,228604#msg-228604)**
>
> Hello, Sometimes I need to regenerate my website. I do not want my users to see semi-generated site. I also do not want google to see 404 errors. The best solution is to return "503" for while I my system generates new files. Is not it? So...

---

<div class="post-metadata">

**Author:** ![IlyaK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f1d935/32.png) [@IlyaK](https://www.ruby-forum.com/u/IlyaK)\
**Post date:** [July 18, 2012, 8:25pm UTC](https://www.ruby-forum.com/t/using-if-f-to-return-503-for-maintenace-good-or-bad/221451/2 "2012-07-18T20:25:46Z")

</div>

Your solution is okay.

Thats the only way if you maintaince your site. Google will come back  
again. And dont get an error 404 or else.

So your search index will not destroy.

Posted at Nginx Forum:

> **[Re: Using "if -f" to return 503 for maintenace: good or bad?](https://forum.nginx.org/read.php?2,228604,228711#msg-228711)**
>
> Hello, Sometimes I need to regenerate my website. I do not want my users to see semi-generated site. I also do not want google to see 404 errors. The best solution is to return "503" for while I my system generates new files. Is not it? So...

---

<div class="post-metadata">

**Author:** ![IlyaK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f1d935/32.png) [@IlyaK](https://www.ruby-forum.com/u/IlyaK)\
**Post date:** [July 19, 2012, 1:07am UTC](https://www.ruby-forum.com/t/using-if-f-to-return-503-for-maintenace-good-or-bad/221451/3 "2012-07-19T01:07:22Z")

</div>

Hello,

a short question about nginx rewrite function. Is it possible  
to rewrite a url like:

[http://domain.com/486ab6c88fd112a89ccgdwd04a3d8275:8d27ce:1.jpg](http://domain.com/486ab6c88fd112a89ccgdwd04a3d8275:8d27ce:1.jpg)

to a path like:

/media/48/6a/486ab6c88fd112a89cc4d9d04a3d8275:8d27ce:1.jpg

i will use the first 4 characters of my filename as 2 subdirectories.  
This was my test, but works not …

location / {  
rewrite “^/([a-z0-9] {2})([a-z0-9] {2})([a-z0-9]+)$”  
/media/$1/$2/$1$2$3  
}

Is there a way i can debug such rewrite rules?

Thanks so much.

Elena

---

<div class="post-metadata">

**Author:** ![IlyaK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f1d935/32.png) [@IlyaK](https://www.ruby-forum.com/u/IlyaK)\
**Post date:** [July 19, 2012, 2:47am UTC](https://www.ruby-forum.com/t/using-if-f-to-return-503-for-maintenace-good-or-bad/221451/4 "2012-07-19T02:47:52Z")

</div>

On Thursday 19 July 2012 03:06:51 Elena Z. wrote:  
[…]

> location / {  
> rewrite “^/([a-z0-9] {2})([a-z0-9] {2})([a-z0-9]+)$” /media/$1/$2/$1$2$3  
> }

rewrite “^/([0-9a-f]{2})([0-9a-f]{2})” /media/$1/$2$uri;

> Is there a way i can debug such rewrite rules?

pcretest

wbr, Valentin V. Bartenev
