Merge pull request #53 from svc-design/codex/update-openresty-vhosts-configuration

feat: split openresty vhost configs by domain
This commit is contained in:
shenlan 2025-08-18 11:05:47 +08:00 committed by GitHub
commit 49bd10e3e0
3 changed files with 46 additions and 53 deletions

View File

@ -38,9 +38,9 @@
- name: Deploy vhost configurations - name: Deploy vhost configurations
template: template:
src: site.conf.j2 src: "{{ item.template }}"
dest: "/usr/local/openresty/nginx/conf/sites-available/{{ item.name }}.conf" dest: "/usr/local/openresty/nginx/conf/sites-available/{{ item.name }}.conf"
loop: "{{ vhosts_openresty_vhosts | default([]) }}" loop: "{{ domain | default([]) }}"
notify: Restart OpenResty notify: Restart OpenResty
- name: Enable and start OpenResty - name: Enable and start OpenResty

View File

@ -0,0 +1,35 @@
{% set name = 'artifact.svc.plus' if 'artifact' in item.name else item.name %}
# {{ name }} 文件下载服务
server {
listen 443 ssl http2;
server_name {{ name }};
ssl_certificate {{ item.ssl_certificate }};
ssl_certificate_key {{ item.ssl_certificate_key }};
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /data/update-server;
index index.html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
location / {
add_header Accept-Ranges bytes;
try_files $uri $uri/ =404;
}
location ~* \.(dmg|zip|tar\.gz|deb|rpm|exe|pkg|AppImage|apk|ipa)$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
add_header Accept-Ranges bytes;
try_files $uri =404;
}
location ~ /\. {
deny all;
}
}

View File

@ -1,63 +1,26 @@
{% set name = item.name %}
lua_package_path "/usr/local/openresty/lualib/?.lua;;"; lua_package_path "/usr/local/openresty/lualib/?.lua;;";
{% for sub in item.subdomains %}
{% if sub.type == 'artifact' %}
# {{ sub.server_name }} 文件下载服务
server {
listen 443 ssl http2;
server_name {{ sub.server_name }};
ssl_certificate {{ sub.ssl_certificate }};
ssl_certificate_key {{ sub.ssl_certificate_key }};
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root {{ sub.root }};
index index.html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
location / {
add_header Accept-Ranges bytes;
try_files $uri $uri/ =404;
}
location ~* \.(dmg|zip|tar\.gz|deb|rpm|exe|pkg|AppImage|apk|ipa)$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
add_header Accept-Ranges bytes;
try_files $uri =404;
}
location ~ /\. {
deny all;
}
}
{% else %}
# HTTP → HTTPS # HTTP → HTTPS
server { server {
listen 80; listen 80;
server_name {{ sub.server_name }}; server_name {{ name }};
return 301 https://{{ sub.server_name }}$request_uri; return 301 https://{{ name }}$request_uri;
} }
# 主站服务 # 主站服务
server { server {
listen 443 ssl http2; listen 443 ssl http2;
server_name {{ sub.server_name }}; server_name {{ name }};
ssl_certificate {{ sub.ssl_certificate }}; ssl_certificate {{ item.ssl_certificate }};
ssl_certificate_key {{ sub.ssl_certificate_key }}; ssl_certificate_key {{ item.ssl_certificate_key }};
ssl_protocols TLSv1.2 TLSv1.3; ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5; ssl_ciphers HIGH:!aNULL:!MD5;
root {{ sub.root }}; root /var/www/XControl/ui/homepage/out;
index index.html; index index.html;
{% if sub.askai_backend is defined %}
# /api/askai 限流:每用户每日 200 次 # /api/askai 限流:每用户每日 200 次
location = /api/askai { location = /api/askai {
access_by_lua_block { access_by_lua_block {
@ -86,26 +49,23 @@ server {
end end
} }
proxy_pass {{ sub.askai_backend }}; proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
{% endif %}
{% if sub.api_backend is defined %}
# 其他 API # 其他 API
location /api/ { location /api/ {
proxy_pass {{ sub.api_backend }}; proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
{% endif %}
# SPA fallback # SPA fallback
location / { location / {
@ -124,5 +84,3 @@ server {
deny all; deny all;
} }
} }
{% endif %}
{% endfor %}