Deploy NGINX-Cluster service with D2C.io

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. 

Denis Zaripov

Product manager

Why Docker?

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.

Preparing

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 icon/bar. 

Creating NGINX-cluster service. Service settings

Name

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. winnie)

Version

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.

Config

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. 

Static

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:

After that, you can serve that NGINX-Cluster by NGINX which can work in HTTP/HTTPS modes and get a link to your app. Check the guide on creating NGINX as an edge service.

Creating NGINX-Cluster service. Advanced settings

Click “Show advanced settings”.

Ports

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.

Configs

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.

Global dependencies 

In this field, you can specify commands for installing global dependencies of your service. 

Initial commands

Commands which are executed only once after deploying a service. 

Environment variables
You can specify environment variables for your application. They can be edited after creating a service.

What next?

In the next article we talk about:

  • maintaining edge services: checking container logs and metrics, updating version