web key to configure the web server running in front of your app.
For single-runtime images, default values might vary based on the image type, which defines the base container used to run the application.
See some examples of how to configure what’s served.
Web commands
pre_start command
The pre_start command is not blocking, which means the deploy hook may start running before the pre_start command finishes. This can lead to unexpected behavior if pre_start performs setup tasks that deploy depends on.To avoid issues, make sure any critical initialization in
pre_start can complete quickly or is safe to run concurrently with deploy.
start command
On all containers other than PHP, it’s a best practice to include a start command. This command runs every time your app is restarted, regardless of whether new code is deployed.
On PHP containers, start is optional and defaults to starting PHP-FPM (/usr/bin/start-php-app).
You can set it explicitly on a PHP container to run a dedicated process,
such as React PHP
or Amp.
See Alternate start commands in the PHP topic.
Do not run a
start process in the background by using & syntax.
The Upsun supervisor interprets that syntax as the command terminating and starts another copy, creating a loop that continues until the container crashes.
Run the command as usual and allow the Upsun supervisor to manage it.post_start command
You can use the post_start command to ensure your app is fully active before traffic is routed to it. This command can perform checks or wait until your application starts listening on the expected port.
For example, if your framework needs several seconds to initialize (for example, to build caches or establish database connections), post_start can help coordinate the handover to ensure that the app receives traffic only after it is initialized.
Example:
This example contains two web commands:- A
startcommand that starts the application every time, whether or not new code is deployed. - A
post_startcommand that repeatedly checks whether a service onlocalhostis responding.
upstream
- Single-runtime image
- Composable image
For PHP, the defaults are configured for PHP-FPM and shouldn’t need adjustment.
For all other containers, the default for
protocol is http.The following example is the default on non-PHP containers:Where to listen
Where to listen depends on your setting forweb.upstream.socket_family (defaults to tcp).
If your application isn’t listening at the same place that the runtime is sending requests,
you see
502 Bad Gateway errors when you try to connect to your website.
locations
Each key in the locations dictionary is a path on your site with a leading /.
For example.com, a / matches example.com/ and /admin matches example.com/admin.
When multiple keys match an incoming request, the most-specific applies.
The following table presents possible properties for each location:
- Single-runtime image
- Composable image
Rules
The rules dictionary can override most other keys according to a regular expression. The key of each item is a regular expression to match paths exactly. If an incoming request matches the rule, it’s handled by the properties under the rule, overriding any conflicting rules from the rest of thelocations dictionary.
Under rules, you can set all the other possible locations properties
except root, index, rules and request_buffering.
In the following example, the allow key disallows requests for static files anywhere in the site.
This is overridden by a rule that explicitly allows common image file formats.
Request buffering
Request buffering is enabled by default to handle chunked requests as most app servers don’t support them. The following table shows the keys in therequest_buffering dictionary:
The default configuration would look like this: