From 0342dfe6418c153740d4cf2d0da81ecd75eee2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Zolt=C3=A1n?= Date: Thu, 6 Mar 2025 19:03:08 +0100 Subject: [PATCH] Nginx enhancements - split configuration (nginx_*.inc stubs) --- .metadata | Bin 14916 -> 15058 bytes .templates/nginx/nginx.conf | 25 ++++++++----------------- .templates/nginx/nginx_nostatic.inc | 11 +++++++++++ .templates/nginx/nginx_static.inc | 10 ++++++++++ tools/customize_nginx.sh | 13 +++++++++---- 5 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 .templates/nginx/nginx_nostatic.inc create mode 100644 .templates/nginx/nginx_static.inc diff --git a/.metadata b/.metadata index 13935af2ee82e076418b6da56bbf5305e9544e27..92838a15acfc00379dbe92fbdb92272e9efb38ee 100644 GIT binary patch delta 238 zcmX?7a;bDfGaC=r!;|R@K(K>1#A5P9QPIf_=3 zR259}Qrdi%gA-L`lC0=t2VsfH@?4WyYObD4pL|eIc5=O>&_sRK$=ZrsljjS{O+IHS zuvv+F0k3jidS+fld|rNWNn%N6vR-ChGDCJ%eoiKo^gaXDFFN_Wro`q`5`B!571RY4 lA)0V#xpxYzMPze?)Ok^!aHvx!vc5H*{6I^3v!B5?P5`eNR@?vp delta 151 zcmcaqdZc7SGaHZagOlkDK=7E$S7`D?QPIi$jG~im#W^NVVBwgYtHitc8ryG1o(V5s zrGiv7DERAczRSVMIC-0p;N&t>rOA?9GkMm1T?01b?W6{&$%zu;lQ%F4Ow?zcWGOUx y9>3V+7%PFzO56*0C+BK$Y!;I2W1O5W!n^si)FDwGhI$server_admin."; } # - # Static service. -# location / { -# root $PAR_SERVICE/storage/volumes/staticweb/; -# allow all; -# autoindex off; -# index index.html index.htm; -# try_files $ri $uri/ =404; -# } + # Optional export backups function. + # Needs ACLs, see the include file. + #include $PAR_SERVICE/configs/nginx_xport.inc; # - # No static service, but we may provide the OPTIONS for a potential DAV client. -# location / { -# types { } default_type text/html; -## dav_ext_methods OPTIONS; -# if ($request_method != OPTIONS) { -# return 404 "Sorry try $scheme://$server_name/$PAR_LOCATION instead."; -## return 302 $scheme://$server_name/$PAR_LOCATION; -# } -# } + # Optional simple static service. + #include $PAR_SERVICE/configs/nginx_static.inc; + # + # Optional simple disabled-static servioe. + #include $PAR_SERVICE/configs/nginx_nostatic.inc; ################################################################################## # The SSL part diff --git a/.templates/nginx/nginx_nostatic.inc b/.templates/nginx/nginx_nostatic.inc new file mode 100644 index 0000000..2218ef2 --- /dev/null +++ b/.templates/nginx/nginx_nostatic.inc @@ -0,0 +1,11 @@ + # Includable nginx configuration. + # + # A simple no-static service. + location / { + types { } default_type text/html; +# dav_ext_methods OPTIONS; + if ($request_method != OPTIONS) { + return 404 "Sorry try $scheme://$server_name/$PAR_LOCATION instead."; +# return 302 $scheme://$server_name/$PAR_LOCATION; + } + } diff --git a/.templates/nginx/nginx_static.inc b/.templates/nginx/nginx_static.inc new file mode 100644 index 0000000..a4dc51b --- /dev/null +++ b/.templates/nginx/nginx_static.inc @@ -0,0 +1,10 @@ + # Includable nginx configuration. + # + # A simple static service. + location / { + root $PAR_SERVICE/storage/volumes/staticweb/; + allow all; + autoindex off; + index index.html index.htm; + try_files $ri $uri/ =404; + } diff --git a/tools/customize_nginx.sh b/tools/customize_nginx.sh index 7efd503..3a3cb7e 100644 --- a/tools/customize_nginx.sh +++ b/tools/customize_nginx.sh @@ -1,11 +1,11 @@ #!/bin/bash -PAR_SERVICENAME= +PAR_SERVICENAME="" PAR_PROXYHOST="localhost" PAR_PROXYPORT="8201" PAR_SERVERNAME="myservice.example.com" PAR_LOCATION= -PAR_WEBMASTER="webmaster@example.com" # Valid support email address +PAR_WEBMASTER="webmaster@example.com" # Valid support email address ################################################################################ # There is nothing to change below this line (I hope) @@ -18,8 +18,13 @@ PAR_SERVICE="$HOME/services/$PAR_SERVICENAME" PARAMETERS='$PAR_ACMEHOST:$PAR_ACMEPORT:$PAR_SERVICE:$PAR_PROXYHOST:$PAR_PROXYPORT:$PAR_SERVERNAME:$PAR_LOCATION:$PAR_WEBMASTER' for parameter in $(echo "$PARAMETERS" | tr ":" "\n") do export ${parameter:1}; done -cat "$PAR_SERVICE/.templates/nginx/nginx.conf" | envsubst "$PARAMETERS" \ - > "$PAR_SERVICE/configs/nginx.conf" +for template in $(cd "$PAR_SERVICE/.templates/nginx/"; ls -1 nginx*) "" +do + if [ -n "$template" ]; then + cat "$PAR_SERVICE/.templates/nginx/$template" | envsubst "$PARAMETERS" \ + > "$PAR_SERVICE/configs/$template" + fi +done touch $PAR_SERVICE/logs/web/access.log $PAR_SERVICE/logs/web/error.log chmod 660 $PAR_SERVICE/logs/web/access.log $PAR_SERVICE/logs/web/error.log