Skip to content

Fix default IPv6 listen_options clash - #1703

Merged
smortex merged 1 commit into
masterfrom
fix-default-ipv6-listen-options-clash
Jun 19, 2026
Merged

Fix default IPv6 listen_options clash#1703
smortex merged 1 commit into
masterfrom
fix-default-ipv6-listen-options-clash

Conversation

@smortex

@smortex smortex commented Jun 17, 2026

Copy link
Copy Markdown
Member

When not explicicly set, $ipv6_listen_options defaults to $listen_options with "ipv6only=on" appended to it.

The nginx documentation gives two important pieces of information regarding the ipv6only parameter:

  1. "This parameter is turned on by default";
  2. "It can only be set once on start".

Source: https://nginx.org/en/docs/http/ngx_http_core_module.html#listen

Because we explicitly set this parameter on each Virtual Host, this leads to broken configuration if multiple virtual hosts are configured.

While one could previously explicitly set ipv6_listen_options => '' to avoid this, the data type was changed in 4ad7bc0 an empty String is not allowed anymore, making the module unusable in such a situation.

This commit adjust the module to not add ipv6only=on by default anymore, relying on the default behavior of nginx to achieve the same result.

It also allows to pass an explicit empty String as $ipv6_listen_options to avoid the default value which match $listen_options.

Last, it adjust the templates to avoid unexpeted spaces in the generated config.

Fixes: #1293
Fixes: #1700
Overcomes: #1701

When not explicicly set, `$ipv6_listen_options` defaults to
`$listen_options` with `"ipv6only=on"` appended to it.

The nginx documentation gives two important pieces of information
regarding the `ipv6only` parameter:

1. "This parameter is turned on by default";
2. "It can only be set once on start".

Source: https://nginx.org/en/docs/http/ngx_http_core_module.html#listen

Because we explicitly set this parameter on each Virtual Host, this
leads to broken configuration if multiple virtual hosts are configured.

While one could previously explicitly set `ipv6_listen_options => ''` to
avoid this, the data type was changed in 4ad7bc0e4and an empty String is
not allowed anymore, making the module unusable in such a situation.

This commit adjust the module to not add `ipv6only=on` by default
anymore, relying on the default behavior of nginx to achieve the same
result.

It also allows to pass an explicit empty String as
`$ipv6_listen_options` to avoid the default value which match
`$listen_options`.

Last, it adjust the templates to avoid unexpeted spaces in the generated
config.
@jay7x

jay7x commented Jun 17, 2026

Copy link
Copy Markdown
Member

Looks like a breaking change 🤔

@smortex smortex added the bug Something isn't working label Jun 17, 2026
@smortex

smortex commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

Looks like a breaking change 🤔

I really consider this a bugfix: the removed parameter was set to its default value, but that value can only be set a single time for a host/port in the configuration. It was bad (and has been bad for a long time), but a workaround was possible until recently, and we cannot use this workaround anymore. So a proper fix was required 😁

But maybe I am missing something, and I don't mind to do a major release after merging this if it makes sense. Can you elaborate about what makes you think this should be considered a breaking change @jay7x ?

@jay7x

jay7x commented Jun 17, 2026

Copy link
Copy Markdown
Member

I'm looking at changes in test files and that looks like behaviour is changed. I had no look at the rest of the code around though.. does it affect existing setups with default settings?

@smortex

smortex commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

does it affect existing setups with default settings

Yes, it fix them* 😉 When updating to the latest release, I had to remove the workaround ipv6_listen_options => '' because it was not allowed anymore, and as a result nginx refused to start because ipv6only=on was set multiple times for the same address+port 😱.
With this change, the workaround is not needed anymore and can be safely removed, but if kept this does not change anything for the user (in fact, I am not 100% sure that allowing ipv6_listen_options => '' makes sense, but it reverts the backward compatibility with older versions of the module, that is the reason I allowed it).

As the removed config is the default one, and cannot be repeated, it feels better to me to not explicitly add it: if the users need to set it to a specific value, they will set it to that value.

*: I do have a bunch of nginx servers with really basic configuration, in reality I believe that this change is very safe, but my use case are quite simple and for this reason I cannot be 100% affirmative that it will not cause any kind of trouble with fancy configurations.

@jay7x

jay7x commented Jun 17, 2026

Copy link
Copy Markdown
Member

I see.. actually, existing installations was my main concern. Read it as "shall we release this change as major or minor release" :)

@smortex
smortex merged commit c5b1ec7 into master Jun 19, 2026
39 of 41 checks passed
@smortex
smortex deleted the fix-default-ipv6-listen-options-clash branch June 19, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipv6_listen_options forces ipv6only on all vhosts Duplicate listen options when using IPv6 with www. redirect

3 participants