-
Notifications
You must be signed in to change notification settings - Fork 18
feat(nginx-proxy): Add wildcard HTTP auth support for WordPress multisite #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix bug where blog.example.com incorrectly checked for _wildcard.blog.example.com instead of _wildcard.example.com. Changes: - 4+ part domains: check 3-part wildcard first, then 2-part fallback - 2-3 part domains: check 2-part wildcard directly - Fixed template formatting to match original style - Updated README with corrected lookup table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds wildcard HTTP basic authentication support specifically designed for WordPress multisite subdomain configurations. It enables a single _wildcard.domain.com htpasswd file to protect both the main domain and all its subdomains.
Key changes:
- Implements cascading wildcard htpasswd lookup logic with support for multi-level TLDs (e.g.,
.co.in,.com.au) - Adds comprehensive documentation explaining the wildcard naming convention and lookup order
- Includes cleanup of trailing whitespace in unrelated parts of the template
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| nginx-proxy/nginx.tmpl | Implements wildcard htpasswd lookup with cascading logic for 2-4+ part domain names, replacing simple default fallback |
| nginx-proxy/README.md | Adds new README with detailed documentation of HTTP auth features, wildcard naming conventions, lookup order, and usage examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| auth_basic "Restricted {{ .Host }}"; | ||
| auth_basic_user_file {{ ($wildcardHtpasswd3) }}; | ||
| {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} | ||
| include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; | ||
| {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} | ||
| include /etc/nginx/vhost.d/default_acl; | ||
| {{ end }} | ||
| {{ else }} | ||
| {{/* Fallback: check last 2 parts (e.g., _wildcard.co.in for blog.domain.co.in) */}} | ||
| {{ $baseDomain2 := printf "%s.%s" (index $hostParts $idx2) (index $hostParts $idx1) }} | ||
| {{ $wildcardHtpasswd2 := printf "/etc/nginx/htpasswd/_wildcard.%s" $baseDomain2 }} | ||
| {{ if (exists $wildcardHtpasswd2) }} | ||
| auth_basic "Restricted {{ .Host }}"; | ||
| auth_basic_user_file {{ ($wildcardHtpasswd2) }}; | ||
| {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} | ||
| include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; | ||
| {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} | ||
| include /etc/nginx/vhost.d/default_acl; | ||
| {{ end }} | ||
| {{ else if (exists "/etc/nginx/htpasswd/default") }} | ||
| auth_basic "Restricted {{ .Host }}"; | ||
| auth_basic_user_file /etc/nginx/htpasswd/default; | ||
| {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} | ||
| include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; | ||
| {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} | ||
| include /etc/nginx/vhost.d/default_acl; | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ else if ge $partsLen 2 }} | ||
| {{/* For 2-3 part domains, check last 2 parts (e.g., _wildcard.example.com for blog.example.com or example.com) */}} | ||
| {{ $idx2 := sub $partsLen 2 }} | ||
| {{ $idx1 := sub $partsLen 1 }} | ||
| {{ $baseDomain2 := printf "%s.%s" (index $hostParts $idx2) (index $hostParts $idx1) }} | ||
| {{ $wildcardHtpasswd2 := printf "/etc/nginx/htpasswd/_wildcard.%s" $baseDomain2 }} | ||
| {{ if (exists $wildcardHtpasswd2) }} | ||
| auth_basic "Restricted {{ .Host }}"; | ||
| auth_basic_user_file {{ ($wildcardHtpasswd2) }}; | ||
| {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} | ||
| include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; | ||
| {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} | ||
| include /etc/nginx/vhost.d/default_acl; | ||
| {{ end }} | ||
| {{ else if (exists "/etc/nginx/htpasswd/default") }} | ||
| auth_basic "Restricted {{ .Host }}"; | ||
| auth_basic_user_file /etc/nginx/htpasswd/default; | ||
| {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} | ||
| include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; | ||
| {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} | ||
| include /etc/nginx/vhost.d/default_acl; | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ else if (exists "/etc/nginx/htpasswd/default") }} | ||
| {{/* Single-part hostname - use default */}} | ||
| auth_basic "Restricted {{ .Host }}"; | ||
| auth_basic_user_file /etc/nginx/htpasswd/default; | ||
| {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} | ||
| include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; | ||
| {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} | ||
| include /etc/nginx/vhost.d/default_acl; | ||
| {{ end }} |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The authentication configuration block (auth_basic, auth_basic_user_file, and ACL includes) is duplicated multiple times throughout this wildcard logic. Consider extracting this into a template macro or function to reduce duplication and improve maintainability. This pattern appears at least 6 times in the new code (lines 87-93, 99-105, 107-113, 123-129, 131-137, 141-147).
| '"$request" $status $body_bytes_sent ' | ||
| '"$http_referer" "$http_user_agent"'; |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation has been changed to use tabs on these lines, which appears inconsistent with the rest of the file. Please verify that the indentation style is intentional and matches the project's coding standards.
| '"$request" $status $body_bytes_sent ' | |
| '"$http_referer" "$http_user_agent"'; | |
| '"$request" $status $body_bytes_sent ' | |
| '"$http_referer" "$http_user_agent"'; |
Summary
Adds wildcard htpasswd file support to enable HTTP basic authentication across WordPress multisite domains using a single htpasswd file.
Features
_wildcard.domain.comapplies HTTP auth todomain.comAND all subdomains (*.domain.com).co.in,.com.au, and other multi-level TLDsLookup Logic
blog.domain.co.in(4 parts)_wildcard.domain.co.in→_wildcard.co.in→defaultdomain.co.in(3 parts)_wildcard.co.in→defaultblog.example.com(3 parts)_wildcard.example.com→defaultexample.com(2 parts)_wildcard.example.com→default