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
Configure static files using the console
To configure the proxy server to serve static files
Open the Elastic Beanstalk console
, and in the Regions list, select your AWS Region. -
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.
In the navigation pane, choose Configuration.
-
In the Updates, monitoring, and logging configuration category, choose Edit.
-
Scroll to the Platform software section and locate the Static files group.
-
To add a static file mapping, select Add static files. In the extra row that appears you'll enter a path for serving static files and the directory that contains the static files to serve.
-
In the Path field, start the path name with a slash (
/
) (for example, "/images"). -
In the Directory field, specify a directory name located in the root of your application's source code. Don't start it with a slash (for example, "static/image-files").
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.
-
-
To remove a mapping, select Remove.
-
-
To save the changes choose Apply at the bottom of the page.
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: