Lagoon
Search…
NGINX-Drupal
The Lagoon nginx-drupal Docker image. Optimized to work with Drupal. Based on Lagoon nginx image.

Lagoon adaptions

This image is prepared to be used on Lagoon. There are therefore some things already done:
  • Folder permissions are automatically adapted with fix-permissions, so this image will work with a random user.
  • To keep drupal.conf 's configuration file as clean and customizable as possible, we added include directives in the main sections of the file:server, location /, location @drupal and location @php.
  • Further information in the section Drupal.conf customization.

Included Drupal configuration (drupal.conf)

The image includes a full NGINX working configuration for Drupal 7, 8 and 9. It includes some extra functionalities like:

Drupal.conf customization

The drupal.conf file is a customized version of the nginx configuration file, optimized for Drupal. Customers have different ways of customizing it:
  • Modifying it (hard to support in case of errors).
  • Using built-in customization through *.conf files.
The drupal.conf file is divided into several sections. The sections we've included in our customizations are:
  • server
  • location /
  • location @drupal
  • location @php.
For each of this section, there are two includes:
  • *_prepend.conf
  • *_append.conf
Here what the location @drupal section looks like:
drupal.conf
1
location @drupal {
2
include /etc/nginx/conf.d/drupal/location_drupal_prepend*.conf;
3
4
include /etc/nginx/fastcgi.conf;
5
fastcgi_param SCRIPT_NAME /index.php;
6
fastcgi_param SCRIPT_FILENAME $realpath_root/index.php;
7
fastcgi_pass ${NGINX_FASTCGI_PASS:-php}:9000;
8
9
include /etc/nginx/conf.d/drupal/location_drupal_append*.conf;
10
}
Copied!
This configuration allows customers to create files called location_drupal_prepend.conf and location_drupal_append.conf, where they can put all the configuration they want to insert before and after the other statements.
Those files, once created, MUST exist in the nginx container, so add them to Dockerfile.nginx like so:
dockerfile.nginx
1
COPY location_drupal_prepend.conf /etc/nginx/conf.d/drupal/location_drupal_prepend.conf
2
RUN fix-permissions /etc/nginx/conf.d/drupal/location_drupal_prepend.conf
Copied!

Drupal Core Statistics Module Configuration

If you're using the core Statistics module, you may run into an issue that needs a quick configuration change.
With the default NGINX configuration, the request to the tracking endpoint /core/modules/statistics/statistics.php is denied (404).
This is related to the default Nginx configuration:
drupal.conf
1
location ~* ^.+\.php$ {
2
try_files /dev/null @drupal;
3
}
Copied!
To fix the issue, we instead define a specific location rule and inject this as a location prepend configuration:
drupal.conf
1
## Allow access to to the statistics endpoint.
2
location ~* ^(/core/modules/statistics/statistics.php) {
3
try_files /dev/null @php;
4
}
Copied!
And copy this during the NGINX container build:
dockerfile.nginx
1
# Add specific Drupal statistics module NGINX configuration.
2
COPY .lagoon/nginx/location_prepend_allow_statistics.conf /etc/nginx/conf.d/drupal/location_prepend_allow_statistics.conf
Copied!
Last modified 8d ago