|
67 | 67 | Supports multi-level TLDs: _wildcard.domain.co.in works for domain.co.in AND *.domain.co.in |
68 | 68 |
|
69 | 69 | Lookup order (after exact match check on line 56): |
70 | | - - For 3+ part domains: checks _wildcard.{last-3-parts}, then falls back to default |
71 | | - - For 2-part domains: checks _wildcard.{domain}, then falls back to default |
| 70 | + - For 4+ part domains: checks _wildcard.{last-3-parts}, then _wildcard.{last-2-parts}, then default |
| 71 | + - For 2-3 part domains: checks _wildcard.{last-2-parts}, then falls back to default |
72 | 72 | - For single-part hostnames: uses default only |
73 | 73 |
|
74 | 74 | Note: Uses sprig's splitList and sub functions (available in docker-gen 0.7.4+) |
75 | 75 | */}} |
76 | 76 | {{ else }} |
77 | 77 | {{ $hostParts := splitList "." .Host }} |
78 | 78 | {{ $partsLen := len $hostParts }} |
79 | | - {{/* Check last 3 parts first (e.g., domain.co.in for blog.domain.co.in) */}} |
80 | | - {{ if ge $partsLen 3 }} |
| 79 | + {{/* For 4+ part domains, check last 3 parts first (e.g., _wildcard.domain.co.in for blog.domain.co.in) */}} |
| 80 | + {{ if ge $partsLen 4 }} |
81 | 81 | {{ $idx3 := sub $partsLen 3 }} |
82 | 82 | {{ $idx2 := sub $partsLen 2 }} |
83 | 83 | {{ $idx1 := sub $partsLen 1 }} |
|
91 | 91 | {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} |
92 | 92 | include /etc/nginx/vhost.d/default_acl; |
93 | 93 | {{ end }} |
94 | | - {{ else if (exists "/etc/nginx/htpasswd/default") }} |
95 | | - auth_basic "Restricted {{ .Host }}"; |
96 | | - auth_basic_user_file /etc/nginx/htpasswd/default; |
97 | | - {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} |
98 | | - include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; |
99 | | - {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} |
100 | | - include /etc/nginx/vhost.d/default_acl; |
| 94 | + {{ else }} |
| 95 | + {{/* Fallback: check last 2 parts (e.g., _wildcard.co.in for blog.domain.co.in) */}} |
| 96 | + {{ $baseDomain2 := printf "%s.%s" (index $hostParts $idx2) (index $hostParts $idx1) }} |
| 97 | + {{ $wildcardHtpasswd2 := printf "/etc/nginx/htpasswd/_wildcard.%s" $baseDomain2 }} |
| 98 | + {{ if (exists $wildcardHtpasswd2) }} |
| 99 | + auth_basic "Restricted {{ .Host }}"; |
| 100 | + auth_basic_user_file {{ ($wildcardHtpasswd2) }}; |
| 101 | + {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} |
| 102 | + include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; |
| 103 | + {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} |
| 104 | + include /etc/nginx/vhost.d/default_acl; |
| 105 | + {{ end }} |
| 106 | + {{ else if (exists "/etc/nginx/htpasswd/default") }} |
| 107 | + auth_basic "Restricted {{ .Host }}"; |
| 108 | + auth_basic_user_file /etc/nginx/htpasswd/default; |
| 109 | + {{ if (exists (printf "/etc/nginx/vhost.d/%s_acl" .Host)) }} |
| 110 | + include {{ printf "/etc/nginx/vhost.d/%s_acl" .Host}}; |
| 111 | + {{ else if (exists "/etc/nginx/vhost.d/default_acl") }} |
| 112 | + include /etc/nginx/vhost.d/default_acl; |
| 113 | + {{ end }} |
101 | 114 | {{ end }} |
102 | 115 | {{ end }} |
103 | 116 | {{ else if ge $partsLen 2 }} |
104 | | - {{/* Only 2 parts (e.g., domain.com) - check wildcard directly */}} |
| 117 | + {{/* For 2-3 part domains, check last 2 parts (e.g., _wildcard.example.com for blog.example.com or example.com) */}} |
105 | 118 | {{ $idx2 := sub $partsLen 2 }} |
106 | 119 | {{ $idx1 := sub $partsLen 1 }} |
107 | 120 | {{ $baseDomain2 := printf "%s.%s" (index $hostParts $idx2) (index $hostParts $idx1) }} |
|
0 commit comments