This guide helps you to deploy an NGINX Cluster in a Docker container using the D2C platform. It must be used for serving PHP-FPM on several hosts. The example is described in the WordPress Scalable stack. The guide might be helpful for beginners as well as for advanced developers.
A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Containers isolate software from its surroundings, for example, differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.
Please, check out the original Docker post about containers for better understanding of all the benefits of the technology.
I’m going to start with a project which already has a deployed PHP-FPM service on three hosts. Follow the guide on creating PHP-FPM if you missed it.
Creating NGINX Cluster service
Let’s click “+Create service” and find the NGINX Cluster bar.
Creating NGINX Cluster service. Service settings
The name should start with a letter and contain up to 16 characters (Latin letters, numbers, hyphen).
Each service has its unique name. Services can communicate with each other by container names (e.g.
winnie-1) or alias-names (e.g.
You can choose a version for your application from a list:
Creating NGINX Cluster service. Configure services
As we mentioned before, NGINX Cluster is suitable for serving PHP-FPM. You can choose PHP-FPM from any project, but it should be on the same host as NGINX Cluster.
Click on “+Add service config” to choose a service for serving.
Let’s start with our PHP-FPM application called Mimi. After a click you can see default settings for PHP-FPM. FastCGI mode is chosen by default.
Clicking on “Generate config“ button, you see an automatically generated config for the selected service:
The config is changeable. Click on “Edit” button if you need to change your config. You can back to defaults using “Generate new config” button.
Serving static is enabled by default for PHP-FPM services. NGINX can serve static only on the same host.
Creating NGINX Cluster service. Select hosts
In most of the cases, it is enough to set a name, version and choose what services NGINX should serve. You can now select hosts and create a service.
NGINX Cluster also has advanced settings. We show them below.
We select here all hosts which are used for PHP-FPM service.
After successful deployment your project should look like:
Creating NGINX Cluster service. Advanced settings
Click “Show advanced settings”.
The first block in this area is Ports.
Access from the Internet is disabled for NGINX Cluster by default. You can enable access from the Internet while creating or editing service.
Persistent data volumes
D2C separates the application itself from its data. Docker volumes are used to store persistent data. Data is stored locally on the hosts.
D2C creates a default
nginx.conf for NGINX Cluster. You can change it using the “Edit” button.
Click on the “Generate new config” button if you need to return to default config.
In this field, you can specify commands for installing global dependencies of your service.
Commands which are executed only once after deploying a service.
In the next article we talk about:
- maintaining edge services: checking container logs and metrics, updating version