I think this might be related, but I figured out a way to run parallel project instances without having to manually override the site name configuration item every time.
In my case, I want to run a local docs site which is static, alongside a WordPress instance. A couple of things I had to do:
- Create a custom web entrypoint that copied a template nginx conf file for the static site into /etc/nginx/sites-enabled. The template was passed through
envsubst
in order to replace the server name with the actual generated site name from DDEV_SITENAME
environment variable.
- Override some Docker Compose configuration in order to get around DDEV's refusal to allow dynamic hostnames based on the calculated site name.
.ddev/docker-compose.router.yaml:
services:
web:
environment:
DDEV_HOSTNAME: ${DDEV_SITENAME}.ddev.site,sphinx-${DDEV_SITENAME}.ddev.site
VIRTUAL_HOST: ${DDEV_SITENAME}.ddev.site,sphinx-${DDEV_SITENAME}.ddev.site
external_links:
- ddev-router:sphinx-${DDEV_SITENAME}.ddev.site
.ddev/nginx_templates/sphinx.conf.template
server {
server_name sphinx-${DDEV_SITENAME}.ddev.site;
root /var/www/html/sphinx/build/html;
listen 80;
listen 443 ssl;
ssl_certificate /etc/ssl/certs/master.crt;
ssl_certificate_key /etc/ssl/certs/master.key;
include /etc/nginx/monitoring.conf;
index index.htm index.html;
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
sendfile off;
error_log /dev/stdout info;
access_log /var/log/nginx/access.log;
location / {
try_files $uri $uri/ =404;
}
# Expire rules for static content
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
access_log off;
}
# Prevent clients from accessing hidden files (starting with a dot)
# This is particularly important if you store .htpasswd files in the site hierarchy
# Access to `/.well-known/` is allowed.
# https://www.mnot.net/blog/2010/04/07/well-known
# https://tools.ietf.org/html/rfc5785
location ~* /\.(?!well-known\/) {
deny all;
}
# Prevent clients from accessing to backup/config/source files
location ~* (?:\.(?:bak|conf|dist|fla|in[ci]|log|psd|sh|sql|sw[op])|~)$ {
deny all;
}
include /etc/nginx/common.d/*.conf;
}
.ddev/web-entrypoint.d/nginx-templates.sh
#!/bin/bash
envsubst '$DDEV_SITENAME' < /mnt/ddev_config/nginx_templates/sphinx.conf.template > /etc/nginx/sites-enabled/sphinx.conf
The obvious caveat is that by doing this you are saying you are going to manually control what the additional_hostnames
configuration would otherwise provide. Personally I find that if I'm running parallel project instances, you can't use additional_hostnames
anyway with how its currently implemented, so its fine. I mandate on all of my DDEV projects that usage of additional_hostnames
is disallowed because parallel instance support is required.