Deploy web static files
Note
Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.
This article applies to: ❌ Basic/Standard ✔️ Enterprise
This article shows you how to deploy your static files to an Azure Spring Apps Enterprise plan instance using the Tanzu Web Servers buildpack. This approach is useful if you have applications that are purely for holding static files like HTML, CSS, or front-end applications built with the JavaScript framework of your choice. You can directly deploy these applications with an automatically configured web server (HTTPD and NGINX) to serve those assets.
Prerequisites
- An already provisioned Azure Spring Apps Enterprise plan instance. For more information, see Quickstart: Build and deploy apps to Azure Spring Apps using the Enterprise plan.
- One or more applications running in Azure Spring Apps. For more information on creating apps, see How to Deploy Spring Boot applications from Azure CLI.
- Azure CLI, version 2.45.0 or higher.
- Your static files or dynamic front-end application - for example, a React app.
Deploy your static files
You can deploy static files to Azure Spring Apps using NGINX or HTTPD web servers in the following ways:
- You can deploy static files directly. Azure Spring Apps automatically configures the specified web server to serve the static files.
- You can create your front-end application in the JavaScript framework of your choice, and then deploy your dynamic front-end application from source code. Azure Spring Apps builds your app into static content and uses your configured web server to serve the static files.
You can also create a server configuration file to customize the web server.
Deploy static files directly
Use the following command to deploy static files directly using an autogenerated default server configuration file.
az spring app deploy
--resource-group <your-resource-group-name> \
--service <your-Azure-Spring-Apps-name> \
--name <your-app-name> \
--source-path <path-to-source-code> \
--build-env BP_WEB_SERVER=nginx
For more information, see the Configure an autogenerated server configuration file section of this article.
Deploy your front-end application as static content
Use the following command to deploy a dynamic front-end application from source code.
az spring app deploy
--resource-group <your-resource-group-name> \
--service <your-Azure-Spring-Apps-name> \
--name <your-app-name> \
--source-path <path-to-source-code> \
--build-env BP_WEB_SERVER=nginx BP_NODE_RUN_SCRIPTS=build BP_WEB_SERVER_ROOT=build
Deploy static files using a customized configuration file
Use the following command to deploy static files using a customized server configuration file.
az spring app deploy
--resource-group <your-resource-group-name> \
--service <your-Azure-Spring-Apps-name> \
--name <your-app-name> \
--source-path <path-to-source-code>
For more information, see the Using a customized server configuration file section of this article.
Sample code
Note
The sample code is maintained by the Paketo open source community.
The Paketo buildpacks samples demonstrate common use cases for several different application types, including the following use cases:
- Serving static files with a default server configuration file using
BP_WEB_SERVER
to select either HTTPD or NGINX. - Using Node Package Manager to build a React app into static files that a web server can serve. Use the following steps:
- Define a script under the
scripts
property of the package.json file that builds your production-ready static assets. For React, it'sbuild
. - Find out where static assets are stored after the build script runs. For React, static assets are stored in
./build
by default. - Set
BP_NODE_RUN_SCRIPTS
to the name of the build script. - Set
BP_WEB_SERVER_ROOT
to the build output directory.
- Define a script under the
- Serving static files with your own server configuration file, using either HTTPD or NGINX.
Configure an autogenerated server configuration file
You can use environment variables to modify the autogenerated server configuration file. The following table shows supported environment variables.
Environment Variable | Supported Value | Description |
---|---|---|
BP_WEB_SERVER |
nginx or httpd | Specifies the web server type, either nginx for Nginx or httpd for Apache HTTP server. Required when using the autogenerated server configuration file. |
BP_WEB_SERVER_ROOT |
An absolute file path or a file path relative to /workspace. | Sets the root directory for the static files. The default is public . |
BP_WEB_SERVER_ENABLE_PUSH_STATE |
true or false | Enables push state routing for your application. Regardless of the route that is requested, index.html is always served. Useful for single-page web applications. |
BP_WEB_SERVER_FORCE_HTTPS |
true or false | Enforces HTTPS for server connections by redirecting all requests to use the HTTPS protocol. |
The following environment variables aren't supported.
BP_LIVE_RELOAD_ENABLED
BP_NGINX_VERSION
BP_HTTPD_VERSION
Using a customized server configuration file
You can configure web server by using a customized server configuration file. Your configuration file must conform to the restrictions described in the following table.
Configuration | Description | Nginx Configuration | Httpd Configuration |
---|---|---|---|
Listening port | Web server must listen on port 8080. The service checks the port on TCP for readiness and whether it's live. You must use the templated variable PORT in the configuration file. The appropriate port number is injected when the web server is launched. |
listen {{PORT}} |
Listen "${PORT}" |
Log path | Config log path to the console. | access_log /dev/stdout , error_log stderr |
ErrorLog /proc/self/fd/2 |
File path with write permission | Web server is granted write permission to the /tmp directory. Configuring the full path requires write permission under the /tmp directory. | For example: client_body_temp_path /tmp/client_body_temp | |
Maximum accepted body size of client request | Web server is behind the gateway. The maximum accepted body size of the client request is set to 500 m in the gateway and the value for web server must be less than 500 m. | client_max_body_size should be less than 500 m. |
LimitRequestBody should be less than 500 m. |
Buildpack bindings
Deploying static files to the Azure Spring Apps Enterprise plan supports the Dynatrace buildpack binding. The htpasswd
buildpack binding isn't supported.
For more information, see How to configure APM integration and CA certificates.
Common build and deployment errors
Your deployment of static files to the Azure Spring Apps Enterprise plan may generate the following common build errors:
ERROR: No buildpack groups passed detection.
ERROR: Please check that you're running against the correct path.
ERROR: failed to detect: no buildpacks participating
The root cause of these errors is that the web server type isn't specified. To resolve these errors, set the environment variable BP_WEB_SERVER
to nginx or httpd.
The following table describes common deployment errors when you deploy static files to the Azure Spring Apps Enterprise plan.
Error message | Root cause | Solution |
---|---|---|
112404: Exit code 0: purposely stopped, please refer to https://aka.ms/exitcode |
The web server failed to start. | Validate your server configuration file to see if there's a configuration error. Then, check whether your configuration file conforms to the restrictions described in the Using a customized server configuration file section. |
mkdir() "/var/client_body_temp" failed (13: Permission denied) |
The web server doesn't have write permission to the specified path. | Configure the path under the directory /tmp; for example: /tmp/client_body_temp. |
Next steps
Feedback
Submit and view feedback for