Serving static files - AWS Elastic Beanstalk
AWS services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with AWS services in China.

Serving static files

To improve performance, you can configure the proxy server to serve static files (for example, HTML or images) from a set of directories inside your web application. When the proxy server receives a request for a file under the specified path, it serves the file directly instead of routing the request to your application.

Elastic Beanstalk supports configuring the proxy to serve static files on most platform branches based on Amazon Linux 2. The one exception is Docker.

Note

On the Python and Ruby platforms, Elastic Beanstalk configures some static file folders by default. For details, see the static file configuration sections for Python and Ruby. You can configure additional folders as explained on this page.

Configure static files using the console

To configure the proxy server to serve static files

  1. Open the Elastic Beanstalk console, and in the Regions list, select your AWS Region.

  2. In the navigation pane, choose Environments, and then choose the name of your environment from the list.

    Note

    If you have many environments, use the search bar to filter the environment list.

  3. In the navigation pane, choose Configuration.

  4. In the Software configuration category, choose Edit.

  5. In the Static files section, enter a path for serving static files and the directory of the static files to serve into the empty row at the bottom of the list.

    Note

    If you aren't seeing the Static files section, you have to add at least one mapping by using a configuration file. For details, see Configure static files using configuration options on this page.

    Start the path with a slash (/). Specify a directory name in the root of your application's source code; don't start it with a slash.

    When you add a mapping, an extra row appears in case you want to add another one. To remove a mapping, click the Remove icon.

    
            Static file configuration in the modify software configuration page of the Elastic Beanstalk console
  6. Choose Apply.

Configure static files using configuration options

You can use a configuration file to configure static file paths and directory locations using configuration options. You can add a configuration file to your application's source bundle and deploy it during environment creation or a later deployment.

If your environment uses a platform branch based on Amazon Linux 2, use the aws:elasticbeanstalk:environment:proxy:staticfiles namespace.

The following example configuration file tells the proxy server to serve files in the statichtml folder at the path /html, and files in the staticimages folder at the path /images.

Example .ebextensions/static-files.config

option_settings: aws:elasticbeanstalk:environment:proxy:staticfiles: /html: statichtml /images: staticimages

If your Elastic Beanstalk environment uses an Amazon Linux AMI platform version (preceding Amazon Linux 2), read the following additional information:

On Amazon Linux AMI platform branches, static file configuration namespaces vary by platform. For details, see one of the following pages: