Repository navigation
Add IPv6 support to macOS port forwarding and nginx - #52
Merged
Merged
Conversation
macOS resolves .test domains to both ::1 (IPv6) and 127.0.0.1 (IPv4), and clients try IPv6 first. The pf redirect rules only handled IPv4, causing connection refused errors. This adds inet6 pf rules and enables IPv6 listen directives in nginx on macOS. Also fixes the upgrade path to always rewrite pf rules on bootstrap, preventing stale rules when the anchor file changes between versions. Related: qoliber#20 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Aquive
force-pushed
the
fix/ipv6-port-forwarding
branch
from
March 30, 2026 12:40
33953c0 to
7b67925
Compare
Collaborator
|
Blind merge since I don't run on Macs :-) |
This was referenced Apr 1, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes connection refused errors on macOS when accessing
.testdomains via HTTPS (or HTTP). This is the macOS counterpart to #20, which solved the same root cause on Linux.Problem
macOS resolves
.testdomains (via/etc/resolver/test) to both::1(IPv6) and127.0.0.1(IPv4). Browsers and curl prefer IPv6 and connect to[::1]:443first. However:inet), so[::1]:443was never forwarded to nginx on port 8443EnableIPv6 = false, so it wasn't listening on[::]:8080/[::]:8443The result: immediate connection refused, with no fallback to IPv4.
#20 addressed this on Linux by adding
[::]:portlisten directives to nginx, noting "macOS is unaffected as it uses port forwarding." Turns out macOS is affected too — just at the pf layer rather than the nginx layer.Changes
internal/portforward/pf.go— Addinet6redirect rules for loopback, bump LaunchDaemon version to4internal/nginx/vhost.go— EnableEnableIPv6 = trueon macOS so nginx listens on[::]:8080and[::]:8443Design decisions
Why always rewrite pf rules on bootstrap?
The original
Setup()only wrote pf rules on fresh install or when the LaunchDaemon version changed. This created a problem: the pf rules file and the LaunchDaemon version could get out of sync (e.g., if the daemon was upgraded but the rules write failed, or if a user ran bootstrap multiple times). Since the rules file is small and writing it is idempotent, we now always write and reload it during bootstrap. The LaunchDaemon still uses version-gated upgrades since it requires unload/load cycles.Why enable IPv6 in nginx on macOS?
Even with IPv6 pf rules redirecting
[::1]:443→[::1]:8443, nginx needs to accept connections on the IPv6 address. EnablingEnableIPv6addslisten [::]:8080andlisten [::]:8443directives to the vhost templates, which is what #20 already did for Linux.Test plan
sudo rm /Library/LaunchDaemons/com.magebox.portforward.plist /etc/pf.anchors/com.magebox), runmagebox bootstrap, verify.testdomains workMageBox-Version-3, runmagebox bootstrap, verify pf rules containinet6lines and.testdomains workcurl -v https://<project>.testconnects via[::1]:443curl --resolve "<project>.test:443:127.0.0.1" https://<project>.testEnableIPv6 = trueand doesn't use pf)🤖 Generated with Claude Code