Skip to content

Conversation

@mrrobot47
Copy link
Member

Summary

Adds wildcard htpasswd file support to enable HTTP basic authentication across WordPress multisite domains using a single htpasswd file.

Features

  • Wildcard naming convention: _wildcard.domain.com applies HTTP auth to domain.com AND all subdomains (*.domain.com)
  • Multi-level TLD support: Works with .co.in, .com.au, and other multi-level TLDs
  • Cascading lookup: Checks exact match → wildcard → default

Lookup Logic

Host Wildcard File Checked
blog.domain.co.in (4 parts) _wildcard.domain.co.in_wildcard.co.indefault
domain.co.in (3 parts) _wildcard.co.indefault
blog.example.com (3 parts) _wildcard.example.comdefault
example.com (2 parts) _wildcard.example.comdefault

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
Copilot AI review requested due to automatic review settings January 8, 2026 05:12
@mrrobot47 mrrobot47 merged commit 409962c into EasyEngine:develop Jan 8, 2026
19 of 20 checks passed
Copy link

Copilot AI left a 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.

Comment on lines +87 to +147
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 }}
Copy link

Copilot AI Jan 8, 2026

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).

Copilot uses AI. Check for mistakes.
Comment on lines +226 to +227
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
Copy link

Copilot AI Jan 8, 2026

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.

Suggested change
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';

Copilot uses AI. Check for mistakes.
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.

1 participant