Mercurial Hosting > luan
changeset 2136:3ca8f933209d nginx_decoupled
Initial; use ~/.nginx-luan/ as nginx master conf dir instead of trying to detect the system default.
| author | Violet7 |
|---|---|
| date | Mon, 19 Jan 2026 19:47:11 -0800 |
| parents | e94d10d071e4 |
| children | 67b504ba388c |
| files | host/check_app.sh host/gen_nginx.sh host/nginx_common.sh host/start_nginx.sh host/startup/nginx/mime.types host/startup/nginx/nginx.conf.luan host/startup/nginx/nginx_master.conf.luan host/stop_nginx.sh host/update2.sh src/luan/host/Https.luan |
| diffstat | 9 files changed, 235 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host/gen_nginx.sh Mon Jan 19 19:47:11 2026 -0800 @@ -0,0 +1,22 @@ +#!/bin/bash +set -e +. nginx_common.sh + +# Function to print the line and the command that failed +error_trap() { + local exit_code=$? + echo "Error: Command failed at line $BASH_LINENO with exit code $exit_code" + exit $exit_code +} + +trap error_trap ERR + +LUANHOST_DIR="$(pwd)" + +cp startup/nginx/mime.types $NGINX_ROOT_CONFIG_DIR +luan startup/nginx/nginx_master.conf.luan $NGINX_ROOT_CONFIG_DIR $NGINX_SITE_CONFIGS_DIR $NGINX_LOG_DIR $NGINX_PID_DIR $NGINX_USER >$NGINX_ROOT_CONFIG_FILE +luan startup/nginx/nginx.conf.luan $LUANHOST_DIR >"$NGINX_SITE_CONFIGS_DIR/luanhost.conf" + +# DON'T put this in the auto-loaded configs dir (NGINX_SITE_CONFIGS_DIR), +# it is not meant to be loaded on its own. +luan startup/nginx/nginx.default.conf.luan $LUANHOST_DIR >"$LUANHOST_DIR/local/luanhost.default.conf"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host/nginx_common.sh Mon Jan 19 19:47:11 2026 -0800 @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +export NGINX_ROOT_CONFIG_DIR="$HOME/.nginx-luan" +export NGINX_ROOT_CONFIG_FILE="$NGINX_ROOT_CONFIG_DIR/nginx.conf" +export NGINX_SITE_CONFIGS_DIR="$NGINX_ROOT_CONFIG_DIR/sites" +export NGINX_LOG_DIR="$NGINX_ROOT_CONFIG_DIR/log" +export NGINX_PID_DIR="$NGINX_ROOT_CONFIG_DIR" +export NGINX_USER="$(whoami)" + +# -p makes this succeed if the path exists on macos +# on linux, mkdir always suceeds if path exists +mkdir -p $NGINX_ROOT_CONFIG_DIR +mkdir -p $NGINX_SITE_CONFIGS_DIR +mkdir -p $NGINX_LOG_DIR +mkdir -p $NGINX_PID_DIR
--- a/host/start_nginx.sh Fri Jan 16 18:15:14 2026 -0800 +++ b/host/start_nginx.sh Mon Jan 19 19:47:11 2026 -0800 @@ -1,4 +1,7 @@ #!/bin/bash -sudo nginx -t -sudo nginx +set -e +. nginx_common.sh + +sudo nginx -c $NGINX_ROOT_CONFIG_FILE -t +sudo nginx -c $NGINX_ROOT_CONFIG_FILE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host/startup/nginx/mime.types Mon Jan 19 19:47:11 2026 -0800 @@ -0,0 +1,101 @@ + +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/avif avif; + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/wasm wasm; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/ogg ogv; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-matroska mkv; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +}
--- a/host/startup/nginx/nginx.conf.luan Fri Jan 16 18:15:14 2026 -0800 +++ b/host/startup/nginx/nginx.conf.luan Mon Jan 19 19:47:11 2026 -0800 @@ -1,4 +1,4 @@ -local luanhostDir, nginxConfigDir, user, group = ... +local luanhostDir = ... %> proxy_cache_path /usr/local/nginx_cache levels=1:2 keys_zone=nginx_cache:60m max_size=10g inactive=60m use_temp_path=off;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host/startup/nginx/nginx_master.conf.luan Mon Jan 19 19:47:11 2026 -0800 @@ -0,0 +1,72 @@ +local nginxRootConfigDir, nginxSiteConfigsDir, nginxLogDir, nginxPidDir, nginxUser = ... + +%> + +# NOTE: this is a manually modified version of /etc/nginx/nginx.conf +# on an ubuntu (pop-os) linux machine. + + +user <%=nginxUser%> <%=nginxUser%>; +worker_processes auto; +pid <%=nginxPidDir%>/nginx.pid; +error_log <%=nginxLogDir%>/error.log; +# Entirely untested, uncomment if modules are needed +# include <%=nginxRootConfigDir%>/modules/*.conf; + +events { + # how was this calculated? + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include <%=nginxRootConfigDir%>/mime.types; + default_type application/octet-stream; + + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log <%=nginxLogDir%>/access.log; + + ## + # Gzip Settings + ## + + gzip on; + + # gzip_vary on; + # gzip_proxied any; + # gzip_comp_level 6; + # gzip_buffers 16 8k; + # gzip_http_version 1.1; + # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + ## + # Virtual Host Configs + ## + + include <%=nginxSiteConfigsDir%>/*.conf; +} + +<%
--- a/host/stop_nginx.sh Fri Jan 16 18:15:14 2026 -0800 +++ b/host/stop_nginx.sh Mon Jan 19 19:47:11 2026 -0800 @@ -1,3 +1,13 @@ #!/bin/bash -sudo nginx -s stop; +set -e +. nginx_common.sh + +NGINX_PID_FILE="$NGINX_PID_DIR/nginx.pid" + +# if file exists and is non empty +if [ -s "$NGINX_PID_FILE" ]; then + sudo nginx -c $NGINX_ROOT_CONFIG_FILE -s stop +else + echo "PID file empty or non existent, doing nothing." +fi
--- a/host/update2.sh Fri Jan 16 18:15:14 2026 -0800 +++ b/host/update2.sh Mon Jan 19 19:47:11 2026 -0800 @@ -13,33 +13,11 @@ openssl genrsa 4096 >local/tiny_account.key fi -nginx_conf_dir=$( - for d in \ - /usr/local/etc/nginx/servers \ - /etc/nginx/conf.d; do - if [ -d "$d" ]; then - echo "$d" - break - fi - done -) - -if [ -n "$nginx_conf_dir" ]; then - echo "using nginx conf dir: $nginx_conf_dir" -else - echo "ERROR: No nginx conf dir found.\nFind it and add it to update2.sh." - exit 1 -fi - -# id -gn gets the name of the primary group of the current user (staff) -luan startup/nginx/nginx.conf.luan $(pwd) $nginx_conf_dir $(whoami) $(id -gn) | sudo tee $nginx_conf_dir/luanhost.conf >/dev/null -# DON'T put this in the auto-loaded configs dir, -# it is not meant to be loaded on its own. -luan startup/nginx/nginx.default.conf.luan $(pwd) >$(pwd)/local/luanhost.default.conf +./gen_nginx.sh # this is done because the nginx conf uses absolute paths # and this breaks sites when the luan/host directory is moved luan classpath:luan/host/update.luan -echo Starting... -./start.sh +echo "(re)Starting..." +./restart.sh
--- a/src/luan/host/Https.luan Fri Jan 16 18:15:14 2026 -0800 +++ b/src/luan/host/Https.luan Mon Jan 19 19:47:11 2026 -0800 @@ -20,6 +20,9 @@ local sys_logger = sys_logging "sys-Https" +-- constants +local NGINX_MASTER_CONF_FILE = "~/.nginx-luan/nginx.conf" + local Https = {} local my_ips = Io.my_ips() @@ -99,14 +102,13 @@ ssl_certificate <%= files.local_cer_file.to_string() %>; ssl_certificate_key <%= files.key_file.to_string() %>; - # path is relative to the dir of the master nginx conf include <%=luanhost_dir.canonical().to_string()%>/local/luanhost.default.conf; } <% end local function reload_nginx(luanhost_dir_str) - local cmd = "sudo nginx -t && sudo nginx -s reload;" + local cmd = "sudo nginx -c "..NGINX_MASTER_CONF_FILE.." -t && sudo nginx -c "..NGINX_MASTER_CONF_FILE.." -s reload;" local s = uri("bash:"..cmd).read_text() logger.info("reload_nginx "..s) end
