diff --git a/conf/nginx.conf b/conf/nginx.conf index 7c50655..f8fc589 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,5 @@ -location __PATH__ { +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { alias __FINALPATH__/ ; if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; diff --git a/scripts/_common.sh b/scripts/_common.sh index 522fde5..746baa4 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -454,6 +454,11 @@ EOF ynh_store_file_checksum "$finalfail2banfilterconf" sudo systemctl restart fail2ban + if local fail2ban_error="$(tail -n50 /var/log/fail2ban.log | grep "WARNING Command.*$app.*addfailregex")" + then + echo "[ERR] Fail2ban fail to load the jail for $app" >&2 + echo "WARNING${fail2ban_error#*WARNING}" >&2 + fi } # Remove the dedicated fail2ban config (jail and filter conf files) diff --git a/scripts/change_url b/scripts/change_url index a56f46b..ca53895 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -68,9 +68,20 @@ then # Make a backup of the original nginx config file if modified ynh_backup_if_checksum_is_different "$nginx_conf_path" - # Replace locations starting with old_path - # Look for every location possible patterns (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location) - ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $old_path" "location\1 $new_path" "$nginx_conf_path" + # Move from sub path to root + if [ "$new_path" == "/" ] + then + ynh_replace_string "^.*rewrite.*\^$old_path" "#sub_path_only&" "$nginx_conf_path" + + ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path" "$nginx_conf_path" + + # Move to a sub path + else + ynh_replace_string "^#sub_path_only" "" "$nginx_conf_path" + ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path/" "$nginx_conf_path" + fi + + ynh_replace_string "location ${old_path%/}/" "location ${new_path%/}/" "$nginx_conf_path" # Calculate and store the nginx config file checksum ynh_store_file_checksum "$nginx_conf_path" diff --git a/scripts/install b/scripts/install index 5e8543d..92ce32c 100644 --- a/scripts/install +++ b/scripts/install @@ -72,6 +72,10 @@ ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie d # NGINX CONFIGURATION #================================================= +if [ "$path_url" != "/" ] +then + ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" +fi ynh_add_nginx_config #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 9ae594c..c6432f3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -92,6 +92,10 @@ ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie d # NGINX CONFIGURATION #================================================= +if [ "$path_url" != "/" ] +then + ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" +fi ynh_add_nginx_config #=================================================