Production Server Configuration
Page last updated:
This topic describes how to configure a production server for your apps.
When you deploy an app, Cloud Foundry determines the command used to start the app through the following process:
If the developer uses the command
cf push -c COMMAND, then Cloud Foundry uses
COMMANDto start the app.
If the developer creates a file called a Procfile, Cloud Foundry uses the Procfile to configure the command that launches the app. See the About Procfiles section below for more information.
If the developer does not use
cf push -c COMMANDand does not create a Procfile, then Cloud Foundry does one of the following, depending on the buildpack:
- Uses a default start command.
- Fails to start the app and shows a warning that the app is missing a Procfile.
One reason to use a Procfile is specify a start command for buildpacks where a default start command is not provided. Some buildpacks, such as Python, that work on a variety of frameworks, do not attempt to provide a default start command.
Another reason to use a Procfile is to configure a production server for web apps.
A Procfile enables you to declare required runtime processes, called process types, for your web app. Process managers in a server use the process types to run and manage the workload. In a Procfile, you declare one process type per line and use the following syntax:
webprocess handles HTTP traffic.
COMMANDis the command line to launch the process.
For example, a Procfile with the following content starts the launch script created by the build process for a Java app:
Follow these steps to specify a web server using a Procfile. For more information about configuring a web server for Rails apps, see the Configure a Ruby Web Server section of this topic.
Create a blank file with a command line for a
Save it as a file named
Procfilewith no extension in the root directory of your app.
Push your app.
Cloud Foundry uses the default standard Ruby web server library WEBrick for Ruby and Ruby on Rails apps. However, Cloud Foundry can support a more robust production web server, such as Phusion Passenger, Puma, Thin, or Unicorn.
To instruct Cloud Foundry to use a web server other than WEBrick, perform the following steps:
Add the gem for the web server to your Gemfile.
configdirectory of your app, create a new configuration file or modify an existing file. Refer to your web server documentation for how to configure this file. The following example uses the Puma web server:
# config/puma.rb threads 8,32 workers 3 on_worker_boot do # things workers do end
In the root directory of your app, create a Procfile and add a command line for a
webprocess type that points to your web server.
For information about configuring the specific command for a process type, see your web server documentation.
The following example shows a command that starts a Puma web server and specifies the app runtime environment, TCP port, and paths to the server state information and configuration files:
web: bundle exec puma -e $RAILS_ENV -p 1234 -S ~/puma -C config/puma.rb