update 2025-04-06
Changes: - fix README.md old json format usage - rename "redirect" option to "proxy_pass" - move docker-compose.yml and nginx.conf.j2 to examples and add to .gitignore - fix situation when one domain from domains.txt and servers.yaml appeared twice in nginx.conf
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Add domain servers to nginx.conf executable script."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
@@ -16,7 +17,7 @@ class Server:
|
||||
|
||||
name: str
|
||||
all_names: str | None = None
|
||||
redirect: str | None = None
|
||||
proxy_pass: str | None = None
|
||||
certificate_dir: str | None = None
|
||||
port: int = None
|
||||
ssl_port: int = None
|
||||
@@ -42,7 +43,7 @@ class Server:
|
||||
return {
|
||||
"name": self.name,
|
||||
"all_names": self.all_names,
|
||||
"redirect": self.redirect,
|
||||
"proxy_pass": self.proxy_pass,
|
||||
"server_options": self.server_options,
|
||||
"location_options": self.location_options,
|
||||
"certificate_dir": self.certificate_dir,
|
||||
@@ -105,19 +106,25 @@ def main() -> None:
|
||||
domains_with_certs = []
|
||||
|
||||
nginx_servers: list[Server] = []
|
||||
resolver: str = "127.0.0.1"
|
||||
acme_challenge_location: str | None = None
|
||||
|
||||
if args.servers_config is not None:
|
||||
with open(args.servers_config, "r", encoding="utf-8") as file:
|
||||
data: dict = yaml.safe_load(file)
|
||||
resolver: str = data.get("resolver", "127.0.0.1")
|
||||
acme_challenge_location: str | None = data.get("acme_challenge_location")
|
||||
resolver: str = data.get("resolver", resolver)
|
||||
acme_challenge_location = data.get("acme_challenge_location")
|
||||
servers: dict[str, dict[str, Any]] = data["servers"]
|
||||
|
||||
for server_name, params in servers.items():
|
||||
nginx_servers.append(
|
||||
Server(
|
||||
name=(server_name if "*" not in server_name else f"{server_name} {server_name.replace('*.', '')}"),
|
||||
all_names=params.get("all_names"),
|
||||
redirect=params.get("redirect"),
|
||||
name=server_name,
|
||||
all_names=params.get(
|
||||
"all_names",
|
||||
None if "*" not in server_name else f"{server_name} {server_name.replace('*.', '', 1)}",
|
||||
),
|
||||
proxy_pass=params.get("proxy_pass"),
|
||||
certificate_dir=_get_certificate_path(
|
||||
args.http_only, domains_with_certs, args.certificates_path, server_name
|
||||
),
|
||||
@@ -130,8 +137,12 @@ def main() -> None:
|
||||
for domain in domains_with_certs:
|
||||
if not any(
|
||||
(
|
||||
domain == server.name
|
||||
or (domain == f"*.{server.name[server.name.find('.') + 1:]}" if "." in server.name else False)
|
||||
(server.all_names is None and domain == server.name)
|
||||
or (
|
||||
server.all_names is not None
|
||||
and f" {domain}" in server.all_names
|
||||
or server.all_names.startswith(domain)
|
||||
)
|
||||
)
|
||||
for server in nginx_servers
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user