Mercurial Hosting > luan
changeset 2102:3112b06ab447 ssltesting
add host/update.luan
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Tue, 16 Dec 2025 16:53:43 -0700 |
| parents | ad0a9ef64827 |
| children | 8c30779427ae |
| files | host/startup/nginx/nginx.ssl.conf.luan host/update.sh src/luan/host/Https.luan src/luan/host/update.luan |
| diffstat | 4 files changed, 57 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/host/startup/nginx/nginx.ssl.conf.luan Mon Dec 15 23:05:49 2025 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -local rootDir, domain = ... - -%> - server { - server_name <%=domain%>; - listen 80; - listen [::]:80; - - location / { - return 301 https://$http_host$request_uri; - } - - location /.well-known/acme-challenge/ { - alias <%=rootDir%>/sites/$host/acme-challenge/; - autoindex on; - } - } - - server { - server_name <%=domain%>; - listen 443 ssl; - listen [::]:443 ssl; - - if ($host != $server_name) { - return 301 http://$http_host$request_uri; - } - - ssl_certificate <%=rootDir%>/sites/<%=domain%>/fullchain.cer; - ssl_certificate_key <%=rootDir%>/sites/<%=domain%>/<%=domain%>.key; - include <%=rootDir%>/local/nginx.default.conf; - } -<%
--- a/host/update.sh Mon Dec 15 23:05:49 2025 -0700 +++ b/host/update.sh Tue Dec 16 16:53:43 2025 -0700 @@ -31,10 +31,7 @@ # this is done because the nginx conf uses absolute paths # and this breaks sites when the luan/host directory is moved -for conf in sites/*/nginx.ssl.conf; do - domain=$(basename $(dirname "$conf")) - luan startup/nginx/nginx.ssl.conf.luan $SCRIPT_DIR $domain >$conf -done +luan classpath:luan/host/update.luan echo Starting... ./start.sh
--- a/src/luan/host/Https.luan Mon Dec 15 23:05:49 2025 -0700 +++ b/src/luan/host/Https.luan Tue Dec 16 16:53:43 2025 -0700 @@ -38,6 +38,48 @@ } end +local function nginx_ssl_conf(domain,files,luanhost_dir) +%> + server { + server_name <%=domain%>; + listen 80; + listen [::]:80; + + location / { + return 301 https://$http_host$request_uri; + } + + location /.well-known/acme-challenge/ { + alias <%= files.acme_challenges.to_string() %>/; + autoindex on; + } + } + + server { + server_name <%=domain%>; + listen 443 ssl; + listen [::]:443 ssl; + + if ($host != $server_name) { + return 301 http://$http_host$request_uri; + } + + ssl_certificate <%= files.local_cer_file.to_string() %>; + ssl_certificate_key <%= files.key_file.to_string() %>; + include <%= luanhost_dir.to_string() %>/local/nginx.default.conf; + } +<% +end + +function Https.update(domain,site_dir,luanhost_dir) + local files = get_files(domain,site_dir) + if files.nginx_file.exists() then + -- sys_logger.info("update "..domain) + local nginx = ` nginx_ssl_conf(domain,files,luanhost_dir) ` + files.nginx_file.write(nginx) + end +end + local function do_set_https(is_https,domain,site_dir,luanhost_dir,dry_run) local files = get_files(domain,site_dir) @@ -143,8 +185,7 @@ -- the nginx config only requires 2 files: -- fullchain.cer and DOMAIN.key logger.info("writing nginx conf to "..files.nginx_file.canonical().to_string()) - local conf = load_file(luanhost_file.."startup/nginx/nginx.ssl.conf.luan") - local nginx = ` conf(luanhost_dir_str,domain) ` + local nginx = ` nginx_ssl_conf(domain,files,luanhost_dir) ` files.nginx_file.write(nginx) end end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/host/update.luan Tue Dec 16 16:53:43 2025 -0700 @@ -0,0 +1,13 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local ipairs = Luan.ipairs or error() +local Io = require "luan:Io.luan" +local Https = require "classpath:luan/host/Https.luan" + + +local luanhost_dir = Io.schemes.file(".").canonical() +local sites_dir = luanhost_dir.child("sites") +for _, site_dir in ipairs(sites_dir.children()) do + local domain = site_dir.name() + Https.update(domain,site_dir,luanhost_dir) +end
