问题
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.
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.
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?
回答1:
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.
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:
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://aws.amazon.com/about-aws/whats-new/2018/07/elastic-load-balancing-announces-support-for-redirects-and-fixed-responses-for-application-load-balancer/
Listener Rules for Your Application Load Balancer: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-update-rules.html
回答2:
It sounds like you are looking for the origin failover functionality https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html which lets you failover to a second origin if requests to the first origin start failing. Alternatively, you could also configure route53 health checks and do the failover at DNS level https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/dns-failover.html
来源:https://stackoverflow.com/questions/59331387/how-to-setup-a-maintenance-page-in-amazon-cloudfront-s3