From 9126cdfeb9fea5d5973750977efbf59e34be283a Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@nsc.liu.se> Date: Mon, 6 May 2024 13:54:38 +0200 Subject: [PATCH] named_vhost: Allow overriding auto-listen. Having the named_vhost definition automatically configure Apache to listen on the address/port pairs used by the virtual host, is usually helpful. There are occasions, however, when it will give unwanted results, or even break things. In particular, if you have overlaps, with one virtual host handling a specific address, and one handling the "wildcard" address (e.g. https://*/), you can't have Apache listen to both INADDR_ANY and a specific address. There may be other cases where users want more control as well. We here introduce a new parameter 'listen' on the apache::named_vhost definition, which specifies addresses (URLs) that Apache httpd should be configured to listen on. If not specified, it defaults to using the same set of addresses as specified by the 'urls' parameter, so in many cases users won't need to specify it. --- manifests/named_vhost.pp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/manifests/named_vhost.pp b/manifests/named_vhost.pp index 8758977..4b08999 100644 --- a/manifests/named_vhost.pp +++ b/manifests/named_vhost.pp @@ -10,12 +10,17 @@ * - urls * Specifies one or more addresses that this virtual host handles, i.e. * which 'Listen' directives apply to it, on the format of URLs, in the - * same format as apache::listen does. apache::listen will be called - * automatically, so you don't need to do that separately (this is a new - * behaviour since 2024). + * same format as apache::listen does. apache::listen will by default + * be called automatically, so you don't need to do that separately + * (this is a new behaviour since 2024). * This parameter can be either a single URL, or a (possibly nested) * list of URLs. * + * - listen + * URLs to listen to, using apache::listen. This will use the value of + * the 'urls' parameter as its default value. Specify the empty list if + * you do not want to generate any Listen directives automatically. + * * - servernames * Which hostnames in URLs this virtual host applies to. Translates * into 'ServerName' and 'ServerAlias' directives. Defaults to the @@ -50,6 +55,7 @@ # e.g. http over https. define apache::named_vhost($urls, + $listen=undef, $servernames=[], $certname=false, $documentroot='', @@ -69,7 +75,7 @@ define apache::named_vhost($urls, } apache::listen { "_vhost-${name}": - urls => $urls; + urls => $listen ? { undef => $urls, default => $listen }; } apache::include_file { "vhost-${name}": -- GitLab