如果我的(Rails)应用程序closures或正在进行数据库维护或其他任何事情,我想在nginx级别指定一个静态页面。 所以像http://example.com/ *这样的每个URL都应该提供一个静态的html文件,比如/var/www/example/foo.html。
试图指定在我的nginxconfiguration是给我适合和无限循环,什么都没有。
我正在尝试的东西
location / { root /var/www/example; index foo.html; rewrite ^/.+$ foo.html; }
你将如何获得你的域上的每个URL来提供一个静态文件?
像这样添加两个位置:
location = /foo.htm { root /var/www/example; index foo.html; } location / { rewrite ^/.+$ /foo.htm; }
我不是100%确定,但如果Rails服务器失败,则会出现错误500.也许您可以使用error_page指令
error_page 500 /staticpage.html
使用指定位置,在redirect期间不会更改URI。
这段代码处理“rails is down”的情况。
error_page 504 @rubydown; # 504 - gateway timeout location @rubydown { internal; root /var/www; rewrite ^ /504.html break; }
为了维护通知,你可以在根目录中使用类似的东西…
location / { root /var/www; try_files /maintaince.html @rails; } location @rails { internal; proxy_pass http://rails.backend; # blablabla proxy_pass setting for Rails }
创build文件/var/www/maintaince.html.tmpl,编写所需的文本。 并在维护工作之前创build类似ln -s /var/www/maintaince.html.tmpl /var/www/maintaince.html simlink或者只是重命名文件。 当维护工作完成后,删除simlink或重新命名文件。
以下内容应将所有请求redirect到/var/www/example/foo.html 。
位置 / {
root / var / www / example;
index foo.html;
#在下面的try_files指令中,请求永远不会达到= 404。
try_files /foo.html = 404;
}