From b7e53d6ca95d8188555a0440cfff5397a23f5ae0 Mon Sep 17 00:00:00 2001 From: shenlan Date: Tue, 19 Aug 2025 14:01:26 +0800 Subject: [PATCH] feat: add vhost defaults and autoindex --- playbooks/deploy_openresty_vhosts.yml | 3 +++ .../OpenResty/templates/artifact.conf.j2 | 19 ++++++++++++++++++- .../roles/vhosts/common/defaults/main.yml | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/playbooks/deploy_openresty_vhosts.yml b/playbooks/deploy_openresty_vhosts.yml index 16c66cf..56316ff 100644 --- a/playbooks/deploy_openresty_vhosts.yml +++ b/playbooks/deploy_openresty_vhosts.yml @@ -38,6 +38,9 @@ - global-artifact.svc.plus ssl_certificate: /etc/ssl/svc.plus.pem ssl_certificate_key: /etc/ssl/svc.plus.rsa.key + root: /data/update-server + autoindex_paths: + - "/" type: artifact roles: - roles/vhosts/common/ diff --git a/playbooks/roles/vhosts/OpenResty/templates/artifact.conf.j2 b/playbooks/roles/vhosts/OpenResty/templates/artifact.conf.j2 index 435197b..9057c3d 100644 --- a/playbooks/roles/vhosts/OpenResty/templates/artifact.conf.j2 +++ b/playbooks/roles/vhosts/OpenResty/templates/artifact.conf.j2 @@ -7,14 +7,31 @@ server { ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; - root /data/update-server; + root {{ item.root | default(vhost_defaults.root) }}; index index.html; + {% set autoindex_paths = item.autoindex_paths | default(vhost_defaults.autoindex_paths) %} + location / { + {% if '/' in autoindex_paths %} + autoindex on; + autoindex_exact_size off; + autoindex_localtime on; + {% endif %} add_header Accept-Ranges bytes; try_files $uri $uri/ =404; } + {% for path in autoindex_paths %} + {% if path != '/' %} + location {{ path }} { + autoindex on; + autoindex_exact_size off; + autoindex_localtime on; + } + {% endif %} + {% endfor %} + location ~* \.(dmg|zip|tar\.gz|deb|rpm|exe|pkg|AppImage|apk|ipa)$ { expires 7d; access_log off; diff --git a/playbooks/roles/vhosts/common/defaults/main.yml b/playbooks/roles/vhosts/common/defaults/main.yml index 368939d..6cd8a8f 100644 --- a/playbooks/roles/vhosts/common/defaults/main.yml +++ b/playbooks/roles/vhosts/common/defaults/main.yml @@ -36,3 +36,8 @@ journald_log_rotation: # 启用 journald 日志管理 # selinux_enable: false # ssh_auth: # key: /root/.ssh/id_rsa.pub + +vhosts: [] +vhost_defaults: + root: /data/update-server + autoindex_paths: []