mirror of
https://github.com/YunoHost-Apps/my_webapp_ynh.git
synced 2024-09-03 19:46:26 +02:00
commit
d91b1bc502
12 changed files with 82 additions and 2 deletions
7
conf/nginx-code-error.conf
Normal file
7
conf/nginx-code-error.conf
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Build error access
|
||||
error_page 403 __PATH__/error/403.html;
|
||||
error_page 404 __PATH__/error/404.html;
|
||||
|
||||
location ^~ __PATH__/error/ {
|
||||
internal;
|
||||
}
|
|
@ -6,7 +6,7 @@ location __PATH__/ {
|
|||
|
||||
# Default indexes and catch-all
|
||||
index index.html index.php;
|
||||
try_files $uri $uri/ __PATH__/index.php?$args;
|
||||
try_files $uri $uri/ __PATH__/index.php?$args =404;
|
||||
|
||||
# Prevent useless logs
|
||||
location = __PATH__/favicon.ico {
|
||||
|
|
|
@ -18,6 +18,15 @@ name = "My Webapp configuration"
|
|||
visible = "with_sftp"
|
||||
help = "If a password already exist, leave blank and it will not be replaced."
|
||||
|
||||
[main.code_error]
|
||||
name = "Html Custom error"
|
||||
|
||||
[main.code_error.custom_error_file]
|
||||
ask = "Activate the custom error file use"
|
||||
type = "boolean"
|
||||
default = false
|
||||
help = "Once custom error enabled, you can add/create a custom `404.html` file in a directory `www\\error`."
|
||||
|
||||
[main.php_fpm_config]
|
||||
name = "PHP-FPM configuration"
|
||||
|
||||
|
|
|
@ -26,6 +26,10 @@ The `php` command will point to the PHP version installed for the app.
|
|||
|
||||
Once logged in, under the Web directory you will see a `www` folder which contains the public files served by this app. You can put all the files of your custom Web application inside.
|
||||
|
||||
### 403 and 404 error handling
|
||||
|
||||
The web server configuration supports http error handling `403` and `404` (access denied and resource not found). Create an `error` folder at `__INSTALL_DIR__/www/error`, and put your `403.html` and `404.html` files in there.
|
||||
|
||||
### Customizing the nginx configuration
|
||||
|
||||
If you want to add tweak the nginx configuration for this app, it is recommended to edit `/etc/nginx/conf.d/__DOMAIN__.d/__ID__.d/WHATEVER_NAME.conf` (ensure that the file has the `.conf` extension) and reload the nginx after making sure that the configuration is valid using `nginx -t`.
|
||||
|
|
|
@ -26,6 +26,10 @@ La commande `php` pointera vers la version de PHP installée pour l'app.
|
|||
|
||||
Après vous être connecté, sous le répertoire Web vous verrez un dossier `www` qui contient les fichiers publics servis par cette application. Vous pouvez mettre tous les fichiers de votre application Web personnalisée à l'intérieur.
|
||||
|
||||
### Gestion des erreurs 403 et 404
|
||||
|
||||
La configuration du serveur web prend en charge la gestion des erreurs http `403` et `404` (accès refusé et ressource non trouvée). Ajoutez un dossier `error` à l'emplacement `__INSTALL_DIR__/www/error`, puis ajoutez-y vos fichiers `403.html` et `404.html`.
|
||||
|
||||
### Personnaliser la configuration nginx
|
||||
|
||||
Si vous souhaitez ajuster la configuration nginx pour cette app, il est recommandé d'éditer `/etc/nginx/conf.d/__DOMAIN__.d/__ID__.d/WHATEVER_NAME.conf` (assurez-vous que le fichier a l'extension `.conf`) puis rechargez nginx après vous être assuré que la configuration est valide à l'aide de `nginx -t`.
|
||||
|
|
|
@ -5,3 +5,5 @@ It can also create a MySQL or PostgreSQL database - which will be backed up and
|
|||
PHP-FPM version can also be selected among `none`, `7.4`, `8.0`, `8.1` and `8.2`.
|
||||
|
||||
**Once installed, go to the chosen URL to know the user, domain and port you will have to use for the SFTP access.** The password is one you chosen during the installation. Under the Web directory, you will see a `www` folder which contains the public files served by this app. You can put all the files of your custom Web application inside.
|
||||
|
||||
You can also customize 404 errors - if you enable the option in the config panel. Simply create an`error` folder in the `www` root directory, containing your custom `html` files.
|
|
@ -5,3 +5,5 @@ Elle peut également créer une base de données MySQL ou PostgreSQL - qui sera
|
|||
La version de PHP-FPM peut aussi être choisie, parmi `none`, `7.4`, `8.0`, `8.1` et `8.2`.
|
||||
|
||||
**Une fois installé, rendez-vous sur l'URL choisie pour connaître l'utilisateur, le domaine et le port que vous devrez utiliser pour l'accès SFTP.** Le mot de passe est celui que vous avez choisi lors de l'installation. Sous le répertoire Web, vous verrez un dossier `www` qui contient les fichiers publics servis par cette application. Vous pouvez mettre tous les fichiers de votre application Web personnalisée à l'intérieur.
|
||||
|
||||
L'application vous permet aussi de gérer - si vous activez l'option dans le panneau de configuration - la gestion des erreurs 404, il vous suffit de créer un dossier `error` dans le répertoire racine `www` et d'y placer vos fichiers d'erreur `html`
|
|
@ -36,6 +36,15 @@ then
|
|||
ynh_backup --src_path="/etc/php/${phpversion}/fpm/pool.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP CUSTOM CONF
|
||||
#=================================================
|
||||
|
||||
if [ $custom_error_file ]
|
||||
then
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.d/error-code.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
|
|
@ -44,6 +44,7 @@ nginx_extra_conf_dir=/etc/nginx/conf.d/$old_domain.d/$app.d
|
|||
|
||||
# Change the path in the NGINX config file
|
||||
if [ $change_path -eq 1 ]
|
||||
ynh_print_info --message="Change the path in the Nginx config file"
|
||||
then
|
||||
# Make a backup of the original NGINX config file if modified
|
||||
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
|
||||
|
@ -52,7 +53,14 @@ then
|
|||
domain="$old_domain"
|
||||
path_url="$new_path"
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
# Update custom error file path if needed
|
||||
if [ $custom_error_file ]
|
||||
ynh_print_info --message="Change the custom error config file"
|
||||
then
|
||||
ynh_add_config --template="nginx-code-error.conf" --destination="$nginx_extra_conf_dir/error-code.conf"
|
||||
fi
|
||||
|
||||
# Create a dedicated NGINX configssh
|
||||
ynh_add_nginx_config
|
||||
fi
|
||||
|
||||
|
@ -62,6 +70,7 @@ then
|
|||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||
ynh_delete_file_checksum --file="$nginx_extra_conf_dir/php.conf"
|
||||
#ynh_delete_file_checksum --file="$nginx_extra_conf_dir/nginx-code-error.conf"
|
||||
|
||||
path_url="$new_path"
|
||||
domain="$old_domain"
|
||||
|
@ -74,6 +83,7 @@ then
|
|||
|
||||
# Store file checksum for the new config file location
|
||||
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.d/php.conf"
|
||||
#ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.d/nginx-code-error.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -148,10 +148,26 @@ ynh_app_config_apply() {
|
|||
ynh_system_user_del_group --username=$app --groups="sftp.app"
|
||||
fi
|
||||
|
||||
if [ "${changed[custom_error_file]}" == "true" ]
|
||||
then
|
||||
CUSTOM_ERROR_FILE=$custom_error_file
|
||||
nginx_extra_conf_dir="/etc/nginx/conf.d/$domain.d/$app.d"
|
||||
|
||||
if [ $custom_error_file -eq 1 ]
|
||||
then
|
||||
ynh_add_config --template="nginx-code-error.conf" --destination="$nginx_extra_conf_dir/error-code.conf"
|
||||
elif [ $custom_error_file -eq 0 ]
|
||||
then
|
||||
ynh_secure_remove --file="$nginx_extra_conf_dir/error-code.conf"
|
||||
fi
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
fi
|
||||
|
||||
if [ "$phpversion" != "none" ]
|
||||
then
|
||||
ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
ynh_app_config_run $1
|
||||
|
|
|
@ -67,6 +67,11 @@ then
|
|||
YNH_PHP_VERSION="$phpversion"
|
||||
fi
|
||||
|
||||
# Add the custom error build with the application
|
||||
ynh_add_config --template="nginx-code-error.conf" --destination="$nginx_extra_conf_dir/error-code.conf"
|
||||
ynh_app_setting_set --app=$app --key=custom_error_file --value="true"
|
||||
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
ynh_add_config --template="example-custom-nginx-config.conf" --destination="$nginx_extra_conf_dir/sample.conf"
|
||||
|
|
|
@ -68,6 +68,12 @@ if [ -z "$phpversion" ]; then
|
|||
ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion
|
||||
fi
|
||||
|
||||
# If custom_error_file doesn't exist, create it.
|
||||
if [ -z "${custom_error_file:-}" ]; then
|
||||
custom_error_file=1
|
||||
ynh_app_setting_set --app=$app --key=custom_error_file --value=$custom_error_file
|
||||
fi
|
||||
|
||||
# Delete old user
|
||||
if [ -n "$(ynh_app_setting_get --app=$app --key=user)" ]
|
||||
then
|
||||
|
@ -102,6 +108,12 @@ then
|
|||
YNH_PHP_VERSION="$phpversion"
|
||||
fi
|
||||
|
||||
# Add the config error code
|
||||
if [ $custom_error_file -eq 1 ]
|
||||
then
|
||||
ynh_add_config --template="nginx-code-error.conf" --destination="$nginx_extra_conf_dir/error-code.conf"
|
||||
fi
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
ynh_add_config --template="example-custom-nginx-config.conf" --destination="$nginx_extra_conf_dir/sample.conf"
|
||||
|
|
Loading…
Add table
Reference in a new issue