I needed to setup a maintenance page for a website which was deployed on elastic beanstalk. As beanstalk doesn’t support a maintenance mode, it fell upon me to create a server to which I can redirect all requests which EB maintenance is going on.

I already had a maintenance page designed and uploaded to S3 as a static website but I needed to make sure all requests are captured by this page while the main server is down. To this end, I setup an nginx proxy which would pass all requests to this static page hosted on S3.

In the nginx conf I made sure that all requests going to my-domain.com would get redirected to the maintenance page on S3. Also, as the assets (images/css/js) were stored in a folder next to the html file, those requests would need to be directed to the S3 asset path. I also added a directive to redirect to the nginx error page instead of the S3 Access Denied page in case a forbidden asset was accessed.

Now all one needs to do is temporarily point the CNAME of the site URL from the beanstalk server to the EC2 Nginx Proxy server.

Here is the conf file: