Сервис приложения
Сервисы/Nginx (Drupal 10)

Сервис Nginx (Drupal 10)

Веб-сервер Nginx с обработкой запросов Drupal, связанный со средой выполнения PHP для Drupal и общими файлами.

Вы добавляете этот сервис в стек и выбираете там его версию и ресурсы. Каждое окружение может их переопределить.

В StackMaster

Как Nginx (Drupal 10) работает в StackMaster

What Wodby sets up for this web server. Check it before adding an nginx.conf to the repository: Nginx here is configured by environment variables and by the config files the service declares, not by files in the codebase.

How it is configured

On every start the container renders its configuration from templates and environment variables: /etc/nginx/nginx.conf, /etc/nginx/conf.d/vhost.conf (one server), /etc/nginx/preset.conf, /etc/nginx/upstream.conf, /etc/nginx/defaults.conf and /etc/nginx/fastcgi.conf. They are rewritten on each start; never edit them in a running container.

To change the configuration:

  • Set NGINX_* environment variables on the service.
  • Change the docroot setting.
  • Override a declared config file: the main config template and the virtual host template of the image. Services built on this one also declare their preset template.

Preset

NGINX_VHOST_PRESET selects the location rules included in the server. This service uses html: files are served from the document root, a directory request serves the index file (NGINX_INDEX_FILE), and a path that matches no file falls back to the index file, which suits a single-page application. The image also ships the presets php, http-proxy, wordpress, laravel, matomo, django and several Drupal versions; services built on this one set the preset for their application.

Document root

The codebase is at /var/www/html. The docroot setting (variable DOCROOT_SUBDIR) names a subdirectory of the repository, and NGINX_SERVER_ROOT is set to /var/www/html/ followed by it. Leave the setting empty to serve the repository root.

Backend link

An optional link to another service sets NGINX_BACKEND_HOST and NGINX_BACKEND_PORT. They form the upstream only for presets that have one: the PHP presets pass PHP requests to it over FastCGI, http-proxy and django proxy HTTP to it. With the html preset the upstream is empty and the link has no effect.

Always present

Unless NGINX_VHOST_NO_DEFAULTS is set, these rules apply with every preset:

  • /.healthz returns 204. Use it for health checks.
  • Paths that start with a dot are denied, except /.well-known/. NGINX_ALLOW_ACCESS_HIDDEN_FILES lifts the rule. wodby.yml and Makefile are denied.
  • /favicon.ico returns an empty image when the file is missing.
  • Response headers X-XSS-Protection, X-Frame-Options, X-Content-Type-Options and Content-Security-Policy are added. The policy only restricts framing; set NGINX_HEADERS_CONTENT_SECURITY_POLICY to change it or NGINX_NO_DEFAULT_HEADERS to drop all four.

Variables that matter most

VariableEffect
NGINX_CLIENT_MAX_BODY_SIZElargest accepted request body, such as an upload
NGINX_STATIC_EXT_REGEXfile extensions treated as static files
NGINX_STATIC_EXPIREScache lifetime sent with static files
NGINX_DISABLE_CACHINGsends no-cache headers for everything
NGINX_INDEX_FILEindex file
NGINX_ERROR_403_URI, NGINX_ERROR_404_URIcustom error pages
NGINX_SERVER_EXTRA_CONF_FILEPATHan extra file included in the server block
NGINX_SET_REAL_IP_FROM, NGINX_REAL_IP_HEADERtrusted proxy and the header holding the client address
NGINX_GZIP, NGINX_BROTLIresponse compression

Access and error logs go to the container's standard output and error.

Build and reaching the service

  • The image is built from the connected repository: the codebase is copied into the image at /var/www/html. Files are served from the built image, so a change needs a new build and deployment.
  • Other services reach it over HTTP on port 80 at the app service's name inside the environment.

Check the result

  • nginx -T prints the configuration in effect.
  • curl -sI localhost/.healthz returns 204 from inside the container.

Nginx for PHP on Wodby

What this service adds to the Nginx service it is based on: it serves a PHP application's static files and passes everything else to the linked PHP service.

How requests are handled

The service sets NGINX_VHOST_PRESET to php:

  • A request for an existing file under the document root is served by Nginx.
  • Any other path is handed to the front controller (NGINX_FASTCGI_INDEX, normally index.php) with the query string, so the application needs no rewrite rules of its own. .htaccess files are not read.
  • A path with a static file extension (NGINX_STATIC_EXT_REGEX) that matches no file returns 404 without reaching PHP. Set NGINX_STATIC_404_TRY_INDEX when the application generates such paths itself.
  • .php requests go to the PHP service over FastCGI.

Backend link

The required backend link must point to a PHP-FPM service. It sets NGINX_BACKEND_HOST and NGINX_BACKEND_PORT, which form the FastCGI upstream.

Nginx passes the script as a path under its own document root, so the PHP service must have the code at the same path. Both images are built from the same source for that reason: this service has no repository of its own and is built from the source of the linked PHP service, copied to /var/www/html.

PHP receives HTTPS from the X-Forwarded-Proto header, so the application sees the original scheme.

Document root

The docroot setting (variable DOCROOT_SUBDIR) defaults to public. NGINX_SERVER_ROOT is /var/www/html/ followed by it. It must be the directory that holds the front controller.

Variables that matter most

In addition to those of the Nginx service: NGINX_FASTCGI_READ_TIMEOUT (how long Nginx waits for PHP), NGINX_FASTCGI_BUFFERS and NGINX_FASTCGI_BUFFER_SIZE, NGINX_FASTCGI_INDEX, NGINX_STATIC_404_TRY_INDEX. Upload size is limited both here (NGINX_CLIENT_MAX_BODY_SIZE) and by the PHP service's own settings.

Static files

Static files are served from the built image: a changed asset needs a new build and deployment of this service.

In a development workspace, the document root subdirectory of the checkout is mounted into this service read-only, so an edited or newly built asset is served without a build or deployment. Nginx cannot write there.

Check the result

  • nginx -T shows the upstream and the document root in effect.
  • curl -sI localhost/ from inside the container returns the application's response when the PHP service is reachable.

Nginx for Drupal 10 on Wodby

What this service adds to the PHP Nginx service it is based on. Check it before adding rewrite rules or web server configuration for Drupal to the repository.

Preset

The service sets NGINX_VHOST_PRESET to drupal10, the image's rule set for Drupal 10. Its template is declared as a config file of this service and can be overridden there. What it does:

  • Paths that match no file go to Drupal's index.php. Clean URLs need no configuration.
  • Only Drupal's entry points run as PHP: index.php, update.php, core/install.php, core/rebuild.php, core/modules/statistics/statistics.php and core/authorize.php. Any other .php path returns 404, so a custom PHP script in the document root is not reachable.
  • Image styles and aggregated CSS and JS under a files directory are served when they exist and generated by Drupal when they do not.
  • sites/<site>/files/private/ is never served directly; /system/files/ goes to Drupal, which controls access.
  • Files with the extensions Drupal's own .htaccess protects (such as .yml, .twig, .module, .sql), composer.json, composer.lock, and the paths /patches and /backup return 404.
  • rss.xml and sitemap.xml are passed to Drupal when no such file exists. Other missing .xml paths return 404 unless NGINX_DRUPAL_ALLOW_XML_ENDPOINTS is set.
  • The default Content-Security-Policy allows framing by the same origin, and Nginx leaves X-Frame-Options and X-Content-Type-Options to Drupal.

Settings shared with the PHP service

The docroot and sitedir settings (variables DOCROOT_SUBDIR and DRUPAL_SITE) are taken from the linked PHP service. Change them there; both services then resolve the Drupal root and the site directory to the same paths.

Files

  • The files volume of the linked PHP service is mounted here read-only at /mnt/files.
  • On start, the service's init action (WODBY2_SERVICE_INIT_ACTION, here init) makes sites/<site>/files under the Drupal root a link to /mnt/files/public, so uploaded public files are served by Nginx directly from the volume.
  • The link cannot be made when sites/<site>/files in the image holds anything other than a .gitignore: keep uploaded files out of the repository.

Build

Only the document root subdirectory of the PHP service's source is copied into this image, at the same path as in the PHP image. Files outside the document root, such as vendor or config, are not in the web server image.

Variables specific to Drupal

NGINX_DRUPAL_FILE_PROXY_URL (redirects requests for missing files under sites/*/files to another site, for an environment without a copy of the files), NGINX_DRUPAL_HIDE_HEADERS, NGINX_DRUPAL_ALLOW_XML_ENDPOINTS, NGINX_DRUPAL_REMOVE_INDEXPHP, NGINX_DRUPAL_NOT_FOUND_REGEX.

Check the result

  • nginx -T shows the preset in effect.
  • ls -l <Drupal root>/sites/<site>/files inside this service shows the link to the files volume.

Обзор

Технический профиль Nginx (Drupal 10)

Здесь перечислены версии, которые можно выбрать для Nginx (Drupal 10) в стеке или окружении. Сам сервис публикуется ревизиями, и стек ссылается на конкретную ревизию.

Тип сервиса

Сервис приложения

Версии

1.31, 1.30

Постоянные тома

Files

Стеки

Стеки, в которые входит Nginx (Drupal 10)

Nginx (Drupal 10) входит в этот публичный стек. Можно создать приложение из публичного стека как есть или добавить сервис в собственный стек.

Конфигурация

Конфигурация сервиса Nginx (Drupal 10)

Сервис Nginx (Drupal 10) объявляет следующее. Если значение можно изменить, его задаёт стек, а каждое окружение может его переопределить.

Технические домены

StackMaster выдаёт каждому публичному HTTP-порту технический домен с TLS-сертификатом и продлевает сертификат. Порт, который сервис помечает как частный, домен не получает. Можно добавить собственные домены.

Тома

Files

Файлы конфигурации

3 файла конфигурации, которые стек или окружение могут переопределить.

Настройки

2 настройки, которые стек или окружение могут изменить.

Связи сервиса

Каждая связь — это подключение Nginx (Drupal 10) к другому сервису. На какой сервис указывает связь, задаёт стек. На карточках перечислены публичные сервисы, которые подходят для каждой связи.