Skip to content

Conversation

@rimi-itk
Copy link
Contributor

@rimi-itk rimi-itk commented Jan 7, 2026

https://leantime.itkdev.dk/_#/tickets/showTicket/6275

  • Replaces "${NGINX_SET_REAL_IP_FROM:-192.168.39.0/24}" with 192.168.39.0/24 in nginx conf templates. See below for details on why.
  • Adds simple nginx conf validation

The details

Using ${name:-…} to set a default value for a non-existing (or empty) environment variable does not work in nginx templates:

$ (cd templates/symfony-6; COMPOSE_DOMAIN=example.com docker compose run --no-deps --rm nginx nginx -t)
…
2026/01/07 11:58:37 [emerg] 1#1: host not found in set_real_ip_from "${NGINX_SET_REAL_IP_FROM:-192.168.39.0/24}" in /etc/nginx/conf.d/default.conf:10
nginx: [emerg] host not found in set_real_ip_from "${NGINX_SET_REAL_IP_FROM:-192.168.39.0/24}" in /etc/nginx/conf.d/default.conf:10
nginx: configuration file /etc/nginx/nginx.conf test failed

Notice "${NGINX_SET_REAL_IP_FROM:-192.168.39.0/24}" is reported, i.e. ${NGINX_SET_REAL_IP_FROM:-192.168.39.0/24} is not replaced with 192.168.39.0/24 as hoped (and expected due to it working in many other places).

It's the nginx docker image that substitutes variables in templates using envsubst, cf. https://github.com/docker-library/docs/tree/master/nginx#using-environment-variables-in-nginx-configuration-new-in-119, but envsubst does not support default values for non-existing variables:

$ (cd templates/symfony-6; COMPOSE_DOMAIN=example.com docker compose run --no-deps --rm nginx sh -c 'envsubst < /etc/nginx/templates/default.conf.template')
server {
    listen 8080;
    server_name localhost;

    root /app/public;

    client_max_body_size 5M;

    set_real_ip_from 172.16.0.0/16;
    set_real_ip_from ${NGINX_SET_REAL_IP_FROM:-192.168.39.0/24};

@rimi-itk rimi-itk force-pushed the hotfix/set_real_ip_from-value branch 5 times, most recently from 86815ff to dc71d9f Compare January 7, 2026 12:21
@rimi-itk rimi-itk force-pushed the hotfix/set_real_ip_from-value branch 2 times, most recently from 0d899a6 to 5327566 Compare January 7, 2026 12:25
@rimi-itk rimi-itk force-pushed the hotfix/set_real_ip_from-value branch from 5327566 to 05c11bc Compare January 7, 2026 12:27
@rimi-itk rimi-itk marked this pull request as ready for review January 7, 2026 12:30
@rimi-itk rimi-itk requested a review from turegjorup January 7, 2026 12:31
Copy link
Contributor

@turegjorup turegjorup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with comment

- name: Validate nginx conf
run: |
COMPOSE_DOMAIN=test.itkdev.dk docker compose --file templates/${{ matrix.version }}/${{ matrix.compose_file}} run --rm nginx nginx -t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a designated example domain:

Reserved Example Second Level Domain Names

The Internet Assigned Numbers Authority (IANA) also currently has the following second level domain names reserved which can be used as examples.

    example.com
    example.net
    example.org

RFC 2606 Reserved Top Level DNS Names June 1999

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dcc85d7.

@rimi-itk rimi-itk requested a review from turegjorup January 7, 2026 12:51
@rimi-itk rimi-itk merged commit dae94fd into develop Jan 7, 2026
34 checks passed
@rimi-itk rimi-itk deleted the hotfix/set_real_ip_from-value branch January 7, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants