From a47af1ed63cf4e59313fd4edc09afaa7e757f33b Mon Sep 17 00:00:00 2001 From: selfhoster1312 Date: Tue, 10 Jan 2023 19:03:08 +0100 Subject: [PATCH] Yunohost panel in parent location block, assets/try_files defined from bash --- conf/nginx.conf | 9 +++++---- scripts/_common.sh | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index e993460..8b49fab 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -12,8 +12,6 @@ location @__NAME__--proxy { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; more_clear_input_headers 'Accept-Encoding'; } @@ -21,6 +19,9 @@ location @__NAME__--proxy { __REDIRECT_BLOCK__ location __PATH_URL_SLASH__ { - alias __ASSETS_PATH__; - try_files $uri @__NAME__--proxy; + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; + + __ASSETS_ALIAS__ + __TRY_FILES__ } diff --git a/scripts/_common.sh b/scripts/_common.sh index 59ddc05..d5b7897 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -26,9 +26,12 @@ rp_validate_proxy_path() { # Verify that the requested assets path is valid # - is a local folder # - ends with a / +# Sets the alias line for serving static files, +# and the try_files line for trying those static files first rp_validate_assets_path() { if [[ "$assets_path" = "" ]]; then - assets_path="/dev/null" + assets_alias="# No static files to serve" + try_files="try_files /dev/null @${app}--proxy;" else if [ ! -d "$assets_path" ]; then ynh_die "Requested assets path "$assets_path" does not exist" 1 @@ -38,17 +41,20 @@ rp_validate_assets_path() { # Append missing trailing / assets_path=""${assets_path}"/" fi + + assets_alias="alias $assets_path;" + try_files="try_files \$uri \$uri/ @${app}--proxy;" fi } # When the app is not in the webroot (path_url = /), need to add a redirect block # to app/ so relative URLs work rp_handle_webroot() { - if [[ "$path_url" = "/" ]]; then - path_url_slash="/" - redirect_block="# Not needed for webroot" - else - path_url_slash=""$path_url"/" - redirect_block="location = "$path_url" { return 302 "$path_url_slash"; }" - fi + if [[ "$path_url" = "/" ]]; then + path_url_slash="/" + redirect_block="# Not needed for webroot" + else + path_url_slash=""$path_url"/" + redirect_block="location = "$path_url" { return 302 "$path_url_slash"; }" + fi }