Hi John,<br><br>That&#39;s an interesting problem.&nbsp; There&#39;s no way that I&#39;ve seen that would let you read the contents of a file from the nginx config.&nbsp; Maybe someone else can shed some light on this.<br><br>In any case, I&#39;m not sure you&#39;d want the overhead of opening and reading a file on every request.&nbsp; However, you might be able to come up with a solution using symlinks and/or a simple cron script that will make the appropriate file available to nginx when necessary.&nbsp; A command like this might work...<br>
<br>if [ -s maintenance_file.txt ]; then ln -s `cat maintenance_file.txt` maintenance.html; elif [ -f maintenance.html ]; then rm maintenance.html; fi<br><br>I tested this out locally, and it works.&nbsp; If the maintenance_file.txt file has text in it, it assumes the text is a filename and creates a symlink to that filename (at a location where nginx would see the symlink and serve the linked file as a maintenance page).&nbsp; If the maintenance_file.txt is empty and the symlink exists, then the symlink is deleted.&nbsp; (This could be made much more robust, but it works as is if the maintenance_file.txt is either empty or contains a single line with no newline/return characters.)<br>
<br>I realize this isn&#39;t exactly what you&#39;re going for, but it might accomplish your goal.&nbsp; And ultimately, this will be more performant than having nginx read the contents of a file on each request.<br><br>Nick<br>
<br><br><div class="gmail_quote">On Fri, Jan 9, 2009 at 11:12 AM, Resicow <span dir="ltr">&lt;<a href="mailto:resicow@gmail.com">resicow@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Nick,<br>
<br>
Thanks for your response... I understand the response below, but I was hoping for a way of doing this by reading the contents of the text file... So something like this...<br>
<br>
 &nbsp; if (-f $document_root/system/back_soon.txt) {<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set $file_to_load read /$document_root/system/back_soon.txt<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rewrite &nbsp;^(.*)$ &nbsp;$file_to_load last;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>
<br>
}<br>
<br>
So if the file exists read and set a variable based on the contents of the file, and then rewrite to the variable path.<br>
<br>
Thanks,<br>
<br>
John<br>
<br>
<br>
<br>
<br>
<br>
Nick Pearson wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">
John,<br>
<br>
See Ezra&#39;s response in the thread here:<br>
<a href="http://thread.gmane.org/gmane.comp.web.nginx.english/8978/focus=8990" target="_blank">http://thread.gmane.org/gmane.comp.web.nginx.english/8978/focus=8990</a><br>
<br>
That explanation is just for a single downtime notice, but you can use a variation of his solution to accomplish what you want. &nbsp;For example:<br>
<br>
server {<br>
 &nbsp; &nbsp;...<br>
 &nbsp; &nbsp;if (-f $document_root/system/back_soon.html) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;rewrite &nbsp;^(.*)$ &nbsp;/system/back_soon.html last;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;break;<br>
 &nbsp; &nbsp;}<br>
 &nbsp; &nbsp;if (-f $document_root/system/down_for_a_while.html) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;rewrite &nbsp;^(.*)$ &nbsp;/system/down_for_a_while.html last;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;break;<br>
 &nbsp; &nbsp;}<br>
 &nbsp; &nbsp;...<br>
}<br>
<br>
This will show the back_soon.html page if it exists. &nbsp;If it doesn&#39;t exist and the down_for_a_while.html page does, then that will be displayed. &nbsp;Otherwise, processing will continue normally.<br>
<br>
<br></div><div class="Ih2E3d">
On Thu, Jan 8, 2009 at 2:05 PM, Resicow &lt;<a href="mailto:resicow@gmail.com" target="_blank">resicow@gmail.com</a> &lt;mailto:<a href="mailto:resicow@gmail.com" target="_blank">resicow@gmail.com</a>&gt;&gt; wrote:<br>
<br>
 &nbsp; &nbsp;Hello Nginx Community, and Happy New Year...<br>
<br>
 &nbsp; &nbsp;Is it possible to set the value of a variable based on the<br>
 &nbsp; &nbsp;contents of a text file?<br>
<br>
 &nbsp; &nbsp;So if there is site downtime, I can place a file in a directory<br>
 &nbsp; &nbsp;that nginx will see and will know to serve a downtime notice, but<br>
 &nbsp; &nbsp;then can nginx read the contents of the file to determine which<br>
 &nbsp; &nbsp;downtime notice to serve?<br>
<br>
 &nbsp; &nbsp;Thanks,<br>
<br>
 &nbsp; &nbsp;John<br>
<br>
<br>
</div></blockquote>
<br>
<br>
</blockquote></div><br>