mirror of
https://github.com/YunoHost-Apps/reverseproxy_ynh.git
synced 2024-09-03 20:16:23 +02:00
Follow recommendations to use more helpers
This commit is contained in:
parent
bc55b0d0ff
commit
ee7c5e9443
7 changed files with 30 additions and 52 deletions
|
@ -1,5 +1,5 @@
|
|||
location @YNH_APPNAME__proxy {
|
||||
proxy_pass YNH_PROXY_PATH;
|
||||
location @__NAME____proxy {
|
||||
proxy_pass __PROXY_PATH__;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
|
@ -18,11 +18,11 @@ location @YNH_APPNAME__proxy {
|
|||
}
|
||||
|
||||
# Support relative URLs
|
||||
location = YNH_LOCATION {
|
||||
return 302 YNH_LOCATION/;
|
||||
location = __PATH_URL__ {
|
||||
return 302 __PATH_URL__/;
|
||||
}
|
||||
|
||||
location YNH_LOCATION/ {
|
||||
alias YNH_ASSETS_PATH;
|
||||
try_files $uri @YNH_APPNAME__proxy;
|
||||
location __PATH_URL__/ {
|
||||
alias __ASSETS_PATH__;
|
||||
try_files $uri @__NAME____proxy;
|
||||
}
|
||||
|
|
|
@ -24,30 +24,3 @@ rp_validate_proxy_path() {
|
|||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Make reverse proxy public if $1 is 1
|
||||
# Yunohost boolean params are 1 if true
|
||||
rp_make_permissions() {
|
||||
ynh_script_progression --message="Configuring permissions..." --weight=2
|
||||
|
||||
if [ $1 = 1 ]; then
|
||||
ynh_permission_update --permission="main" --add="visitors"
|
||||
fi
|
||||
}
|
||||
|
||||
# (re)generate nginx config
|
||||
rp_make_webconfig() {
|
||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
||||
|
||||
# Nginx configuration
|
||||
ynh_replace_string "YNH_LOCATION" "$path_url" ../conf/nginx.conf
|
||||
ynh_replace_string "YNH_PROXY_PATH" "$proxy_path" ../conf/nginx.conf
|
||||
ynh_replace_string "YNH_APPNAME" "$app" ../conf/nginx.conf
|
||||
ynh_replace_string "YNH_ASSETS_PATH" "$assets_path" ../conf/nginx.conf
|
||||
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
}
|
||||
|
||||
rp_reload_web() {
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
}
|
||||
|
|
|
@ -33,15 +33,17 @@ new_path=$YNH_APP_NEW_PATH
|
|||
#=================================================
|
||||
|
||||
# Nginx configuration
|
||||
ynh_replace_string "$old_path {" "$new_path {" /etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
ynh_replace_string "${old_path}/ {" "${new_path}/ {" /etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
ynh_replace_string "302 ${old_path}/" "302 ${new_path}/" /etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
path_url="$new_path"
|
||||
domain="$old_domain"
|
||||
proxy_path="$(ynh_app_setting_get --app=$app --key=proxy_path)"
|
||||
assets_path="$(ynh_app_setting_get --app=$app --key=assets_path)"
|
||||
ynh_add_nginx_config
|
||||
|
||||
# Maybe only path part has changed... only move file if domain has changed
|
||||
# Move file to new domain if domain has changed
|
||||
[[ "$old_domain" != "$new_domain" ]] && mv /etc/nginx/conf.d/$old_domain.d/$app.conf /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
|
||||
# Reload nginx
|
||||
rp_reload_web
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -44,13 +44,15 @@ ynh_app_setting_set --app=$app --key=proxy_path --value=$proxy_path
|
|||
ynh_app_setting_set --app=$app --key=assets_path --value=$assets_path
|
||||
|
||||
# Configure nginx
|
||||
rp_make_webconfig
|
||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
ynh_add_nginx_config
|
||||
|
||||
# Make app public if necessary
|
||||
rp_make_permissions $is_public
|
||||
|
||||
# Reload nginx
|
||||
rp_reload_web
|
||||
# Make app public if necessary (yunohost setting boolean is 1 when true)
|
||||
ynh_script_progression --message="Configuring permissions..." --weight=2
|
||||
if [ $is_public -eq 1 ]; then
|
||||
ynh_permission_update --permission="main" --add="visitors"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -26,7 +26,8 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|||
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
|
||||
# Reload nginx
|
||||
rp_reload_web
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -42,7 +42,8 @@ NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|||
ynh_restore_file "$NGINX_CONF"
|
||||
|
||||
# Reload nginx
|
||||
rp_reload_web
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -42,10 +42,9 @@ ynh_abort_if_errors
|
|||
rp_validate_proxy_path "$proxy_path"
|
||||
|
||||
# Configure nginx
|
||||
rp_make_webconfig
|
||||
|
||||
# Reload nginx
|
||||
rp_reload_web
|
||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
Loading…
Reference in a new issue