如何在Amazon CloudFront/S3中设置维护页面 [英] How to setup a maintenance page in Amazon CloudFront /S3

查看:65
本文介绍了如何在Amazon CloudFront/S3中设置维护页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将AWS S3用于前端Web托管,并将AWS EC2用于后端托管.EC2实例位于elb后面并已安排了维护,我想在EC2实例处于维护状态时显示维护页面.

I'm using AWS S3 for front-end web hosting and AWS EC2 for back-end hosting. The EC2 instance is behind an elb and has scheduled maintenance, and I want to display a maintenance page when the EC2 instance is under maintenance.

我设置它的方式是让index.html在EC2上触摸"某些文件,如果服务器不可用,它将返回HTTP 503错误.S3中有一个503.html,当发生503错误时,我想显示它.

The way that I set it up is to let index.html "touch" some files on EC2, if the server is unavailable it will return HTTP 503 error. There is a 503.html in S3 and I want to display it when 503 error happens.

我尝试创建一个新的CloudFront错误页面并创建S3重定向规则,但是这些规则均无效.设置维护页面的最佳方法是什么?

I've tried creating a new CloudFront Error Page and creating S3 Redirection rules, but none of them is working. What is the best way to set up the maintenance page?

推荐答案

我一直在寻找实现此目的的快速方法.在数据库升级期间,我们需要向世界返回503错误,但白名单列出了一些开发人员的IP,以便他们在重新公开之前可以对其进行测试.

I've been searching for a quick way to do this. We need to return a 503 error to the world during DB upgrade, but white list a few IPs of developers so they can test it before opening back up to public.

找到了一个单点解决方案::转到EC2中的Loader Balancer,然后选择要定位的负载均衡器.在下面,您应该看到侦听器.单击一个侦听器,然后编辑规则.创建如下规则:

Found a one spot solution:: Go to the Loader Balancer in EC2 and select the load balancer you would like to target. Below, you should see Listeners. Click on a listener, and edit the rule. Create a rule like this:

现在,每个人都会获得一个漂亮的维护页面,并返回503错误代码,并且第一个规则中只有两个IP地址将能够浏览到该站点.顺序很重要,两个IP例外在最上面,然后在列表中排在后面.默认情况下,最后一项始终存在.

Now everyone gets a pretty maintenance page returned with a 503 error code, and only two IP addresses in the first rule will be able to browse to the site. Order is important, where the two IP exceptions are on top, then it goes down the list. The last item is always there by default.

侦听器规则: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-update-rules.html

这篇关于如何在Amazon CloudFront/S3中设置维护页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆